题意:给一个长度最多为30的数,问是否能被2,3或者5整除
思路:按照字符串存储,判断最后一个数是不是2的倍数、5,以及判断各个位相加是否能被3整除
Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 130 Accepted Submission(s): 86
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)
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
<pre name="code" class="cpp">#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <time.h>
#include <set>
#include <map>
#include <stack>
using namespace std;
typedef long long LL;
const int INF=0x7fffffff;
const int MAX_N=10000;
//long long n;
char A[100];
int main(){
while(scanf("%s",&A)!=EOF){
if(A[strlen(A)-1]=='0'||A[strlen(A)-1]=='5'){
printf("YES\n");
continue;
}
if((A[strlen(A)-1]-'0')%2==0){
printf("YES\n");
continue;
}
int ans=0;
for(int i=0;i<strlen(A);i++){
ans+=A[i]-'0';
}
if(ans%3==0){
printf("YES\n");
continue;
}
else printf("NO\n");
}
return 0;
}