本文共 731 字,大约阅读时间需要 2 分钟。
There is a number N.You should output "YES" if N is a multiple of 2, 3 or 5,otherwise output "NO".
There are multiple test cases, no more than 1000 cases.
For each case,the line contains a integer N.(0<N<10^30)
For each test case,output the answer in a line.
2 3 5 7
YES YES YES NO
水题。但是要注意的是N是小于10^30,非常大,所以可以用字符数组来存储。
如果N的各个位的数字之和%3==0,那么就是3的倍数。
例:
123%3==0 ,1+2+3=6%3==0
789%3==0 ,7+8+9=24%3==0
55%3!=0 ,5+5=10%3!=0
如果N的个位数%2==0,那么就是2的倍数。
如果N的个位数%5==0,那么就是5的倍数。
#include#include #include #include using namespace std;int main(){ char s[107]; while(scanf("%s",s)!=EOF) { int len=strlen(s); int sum=0; for(int i=0;i
转载地址:http://yvzci.baihongyu.com/