Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 217 Accepted Submission(s): 151
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
Recommend
题目大意:
给一个数N,如果N是2、3或者5的倍数,输出"YES",否则输出"NO".
解体思路:
注意数据范围,用字符串来做。。。比较水代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
#define MM(a) memset(a,0,sizeof(a))
typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 1e5+5;
const int mod = 1e4+7;
const double eps = 1e-10;
const int INF = 0x3f3f3f3f;
LL gcd(LL a, LL b)
{
if(b == 0)
return a;
return gcd(b, a%b);
}
char str[maxn];
int main()
{
while(cin>>str)
{
int len = strlen(str);
LL sum = 0;
for(int i=0; i<len; i++)
sum += str[i]-'0';
if(sum%3==0 || (str[len-1]-'0')%2==0 || str[len-1]-'0'==5)
puts("YES");
else
puts("NO");
}
return 0;
}