Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#define LL long long
#define INF 0x3f3f3f3f
#define RR freopen("in.txt","r",stdin)
#define WW freopen("out.txt","w",stdout)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
int main()
{
char s[1010];
while(cin>>s)
{
int sum = 0;
int len = strlen(s);
for(int i=0; i<len; i++)
sum += (s[i] - '0');
if(sum % 3 == 0 || (s[len-1] - '0')%2==0 || s[len-1] - '0'==5)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
此博客介绍了如何通过简单的算法判断一个给定的整数是否为2、3或5的倍数,并提供了实现该功能的代码示例。
353

被折叠的 条评论
为什么被折叠?



