hdu 5585 Numbers【大数+同余定理】

Numbers

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 460    Accepted Submission(s): 283


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)
 

 

Output
For each test case,output the answer in a line.
 

 

Sample Input
2
3
5
7
 

 

Sample Output
YES
YES
YES
NO
 
注意:n是大数,求n是否是2或者3或者5的倍数
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define LL long long
#define MAX 1010
using namespace std;
int main()
{
	LL n,m,j,i,k;
	char s[50];
	while(scanf("%s",s)!=EOF)
	{
		int len=strlen(s);
		int sum1,sum2,sum3;
		sum1=sum2=sum3=0;
		for(i=0;i<len;i++)
		{
			sum1=sum1*10+s[i]-'0';
			sum1=sum1%2;
			sum2=sum2*10+s[i]-'0';
			sum2=sum2%3;
			sum3=sum3*10+s[i]-'0';
			sum3=sum3%5;
		}
		if(sum1==0||sum2==0||sum3==0)
		printf("YES\n");
		else
		printf("NO\n");
	}
	return 0;
} 

  

 
posted @ 2015-12-04 12:38  非我非非我  阅读(212)  评论(0编辑  收藏  举报