hdu 5585

Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2269    Accepted Submission(s): 838


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

 判断n是不是2,3,5的倍数

判断2,5,只要判断末尾是不是0,或者2,5的倍数,,所以只要对2,5求余,,二判断是不是3的倍数,只要所有的数加起来对3求余就好

 1 #include <iostream>
 2 #include <vector>
 3 #include <algorithm>
 4 #include <string>
 5 #include <string.h>
 6 #include <cstring>
 7 #include <stdio.h>
 8 #define lowbit(x) x&(-x)
 9 
10 using namespace std;
11 const int maxn=1e5+10;
12 typedef long long ll;
13 
14 int main(){
15     ios::sync_with_stdio(0);
16     string s;
17     while(cin>>s){
18         int len=s.length();
19         int sum=0;
20         for(int i=0;i<s.length();i++){
21             sum+=s[i]-'0';
22         }
23         if(sum%3==0||((s[len-1]-'0')%2==0)||((s[len-1]-'0')%5==0)){
24             cout<<"YES"<<endl;
25         }
26         else {
27             cout<<"NO"<<endl;
28         }
29     }
30     return 0;
31 }
原文地址:https://www.cnblogs.com/z-712/p/8733903.html