HDOJ:5585
Problem Description
There is a number N.You should output "YES" if N is a multiple of 2, 3 or 5,otherwise output "NO".
Input
There are multiple test cases, no more than 1000
cases.
For each case,the line contains a integer N.(0<N<10
30
)
For each case,the line contains a integer N.(0<N<10
Output
For each test case,output the answer in a line.
Sample Input
2
3
5
7
Sample Output
YES
YES
YES
NO
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
char a[40];
while(scanf("%s",a)!=EOF)
{
int i,m,sum,count=0;
m=strlen(a);
sum=0;
for(i=0;i<m;i++){
sum+=a[i]-'0';
}
if(sum%3==0)//判断能否被3整除
{
cout<<"YES"<<endl;
count=1;//用于输出
}
else
{
sum=0;
sum=a[m-1]-'0';
if(sum%2==0||sum%5==0)//判断
{
cout<<"YES"<<endl;
count=1;//用于输出
}
}
if(count==0)
cout<<"NO"<<endl;
}
return 0;
}

浙公网安备 33010602011771号