Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 449 Accepted Submission(s): 280
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
题目链接:点击打开链接
根据题目范围, 字符串读入, 判断是不是2的倍数只要判断最后一位是不是0, 2, 4, 6, 8, 判断是不是5的倍数只要判断最后一位是不是5, 判断是不是3的倍数只要判断每位和是不是3的倍数即可.
AC代码:
#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 50;
char s[MAXN];
int main(int argc, char const *argv[])
{
while(scanf("%s", s) != EOF) {
int len = strlen(s), sum = 0;
char c = s[len - 1];
for(int i = 0; i < len; ++i)
sum += s[i] - '0';
if(c == '0' || c == '2' || c == '4' || c == '5' || c == '6' || c == '8' || sum % 3 == 0) printf("YES\n");
else printf("NO\n");
}
return 0;
}