您的位置:首页 > 其它

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]

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去余,这样剩下的数不会影响结果,也不会超出范围。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: