hdoj5585Numbers
2015-12-15 19:52
281 查看
[align=left]Problem Description[/align]
There is a number N.You should output "YES" if N is a multiple of 2, 3 or 5,otherwise output "NO".
[align=left]Input[/align]
There are multiple test cases, no more than 1000 cases.
For each case,the line contains a integer N.(0<N<10
30
)
[align=left]Output[/align]
For each test case,output the answer in a line.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
There is a number N.You should output "YES" if N is a multiple of 2, 3 or 5,otherwise output "NO".
[align=left]Input[/align]
There are multiple test cases, no more than 1000 cases.
For each case,the line contains a integer N.(0<N<10
30
)
[align=left]Output[/align]
For each test case,output the answer in a line.
[align=left]Sample Input[/align]
2 3 5 7
[align=left]Sample Output[/align]
YES YES YES NO代码:#include<stdio.h> #include<string.h> int main() { char a[10000]; int b,i; while(scanf("%s",a)!=EOF) { long long sum=0; b=strlen(a); for( i=0;i<=b-1;i++) { sum=(sum*10+a[i]-'0')%30; } if(sum%2==0||sum%3==0||sum%5==0) printf("YES\n"); else printf("NO\n"); } return 0; } 思路:判断是否能整除2,3或5,我用的方法是先对30去余,这样剩下的数不会影响结果,也不会超出范围。
相关文章推荐
- JAVA设计模式之享元模式
- bzoj3620(KMP)
- NSDictionary 、 NSMutableDictionary
- 关于oracle with as用法
- NSArray(二) 、 NSMutableArray 、 NSSet 、 NSMutableSet
- 代码对比看:&& || %errorlevel%的区别
- 互联网协议入门(一)
- python :逻辑行被分成两个物理行的解决方法
- hdoj2803The MAX
- JAVA设计模式之门面模式(外观模式)
- NSNumber 、 NSValue 、 日期处理 、 集合类 、 NSArray(一)
- [深入Maven源代码]maven绑定命令行参数到具体插件
- StringUtils中 isNotEmpty 和isNotBlank的区别
- Mysql Cluster基于时间点的恢复
- Java基础---网络编程
- 使用java开发文本全局搜索器
- hdoj2096小明A+B
- 第六篇 Java编译器与C/C++编译器的比较
- C++ strcpy、strcat、strcmp和strlen的实现
- 海康大华PC客户端集成播放器