5585】Numbers (水題,數學,數論)
阿新 • • 發佈:2019-01-10
題幹:
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)(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,3,5的倍數。
AC程式碼:
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define ll long long using namespace std; char s[100005]; int main() { while(~scanf("%s",s+1)) { int len = strlen(s+1); ll sum = 0; for(int i = 1; i<=len; i++) { sum += s[i] - '0'; } if(sum%3==0 || (s[len] - '0') %2 == 0 || (s[len] - '0' == 5)) puts("YES"); else puts("NO"); } return 0 ; }