hdu 5585 Numbers

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<1030)
 
Output
For each test case,output the answer in a line.
 
Sample Input
2
3
5
7
Sample Output
YES
YES
YES
NO
 
Source
 
读入%s字符串
2和5看大数的最后一位,3就把所有的位加起来看看是不是3的倍数
 
 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<math.h>
 7 #include<algorithm>
 8 #include<queue>
 9 #include<set>
10 #include<bitset>
11 #include<map>
12 #include<vector>
13 #include<stdlib.h>
14 #include <stack>
15 using namespace std;
16 #define PI acos(-1.0)
17 #define max(a,b) (a) > (b) ? (a) : (b)
18 #define min(a,b) (a) < (b) ? (a) : (b)
19 #define ll long long
20 #define eps 1e-10
21 #define MOD 1000000007
22 #define N 1000000
23 #define inf 1e12
24 char s[36];
25 int main()
26 {
27 
28 
29      while(scanf("%s",s)!=EOF){
30          int len=strlen(s);
31          //printf("len=%d
",len);
32          int sum=0;
33          for(int i=0;i<len;i++){
34             sum=sum+s[i]-'0';
35          }
36          //printf("sum=%d
",sum);
37          if(sum%3==0){
38             printf("YES
");
39             continue;
40          }
41          int ans=s[len-1]-'0';
42          //printf("ans=%d
",ans);
43          if((ans==0) || (ans==2) || (ans==4) || (ans==6) || (ans==8) || (ans==5)){
44             printf("YES
");
45             continue;
46          }
47          printf("NO
");
48      }
49 
50 
51     return 0;
52 }
View Code
 
原文地址:https://www.cnblogs.com/UniqueColor/p/5005060.html