Numbers
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
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
/************************************************************************/
附上该题对应的中文题
Numbers
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
问题描述
给一个数N,如果N是2、3或者5的倍数,输出"YES",否则输出"NO".
输入描述
输入有多组数据,不超过1000组.
每组数据输入一行包含一个整数N.(0<N<1030)
输出描述
对于每组数据输出一行答案.
输入样例
2 3 5 7
输出样例
YES YES YES NO
/****************************************************/
出题人的解题思路:
Numbers
判断是否是2或者5的倍数只看最后一位,判断3时统计十进制下每一位之和是否是3的倍数。
最近眼神不太好使了,居然直接当成
了,再加上看到水题有点小激动,然后水水地交了一发,WA
if(n%2==0||n%3==0||n%5==0)
然后就哭了,orz
由于已经超过了long long(或__int64)的范围,所以理所当然应该字符串输入,判断各位数之和能否被3整除,还有就是s[strlen(s)-1]位-'0'之后是否能被2或者5整除
本题的hack点在于,你如果没用字符串,而是用了__int64或long long的话,也是可以过初始数据的,所以hack数据可为27个1
即111111111111111111111111111
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10
using namespace std;
const int N = 1005;
const int M = 10005;
const int inf = 1000000000;
const int mod = 2009;
char s[N];
int main()
{
int i,sum,j;
while(~scanf("%s",&s))
{
sum=0;j=strlen(s);
for(i=0;s[i]!='\0';i++)
sum+=(s[i]-'0');
if((s[j-1]-'0')%2==0||(s[j-1]-'0')%5==0||sum%3==0)
puts("YES");
else
puts("NO");
}
return 0;
}
菜鸟成长记