BestCoder Round #64 (div.2) A Numbers&&HDU 5585

Numbers

 
 Accepts: 480
 
 Submissions: 1518
 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<{10}^{30})(0<N<1030)
输出描述
对于每组数据输出一行答案.
输入样例
2
3
5
7
输出样例
YES
YES
YES
NO

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxm=1e3+10;
char s[maxm];
int main()
{
    while(scanf("%s",s)!=EOF)
    {
        int sum1=0,sum2=0,sum3=0;
        int len=strlen(s);
        for(int i=0;i<len;i++)
        {
            sum1=(sum1*10+s[i]-'0')%2;
        }
        for(int i=0;i<len;i++)
        {
            sum2=(sum2*10+s[i]-'0')%3;
        }
        for(int i=0;i<len;i++)
        {
            sum3=(sum3*10+s[i]-'0')%5;
        }
        if(sum1==0||sum2==0||sum3==0)
        {
            printf("YES\n");
        }
        else
        {
            printf("NO\n");
        }
    }
    return 0;
}

//JAVA大数来一发
import java.util.*;
import java.math.BigInteger;
public class Main{
    public static void main(String[] args)
    {
        Scanner cin=new Scanner(System.in);
        while(cin.hasNext())
        {
            BigInteger n=cin.nextBigInteger();
            BigInteger x=new BigInteger("2");
            BigInteger y=new BigInteger("3");
            BigInteger z=new BigInteger("5");
            BigInteger x1=n.mod(x);
            BigInteger y1=n.mod(y);
            BigInteger z1=n.mod(z);
            BigInteger a=new BigInteger("0");
            if(x1.compareTo(a)==0||y1.compareTo(a)==0||z1.compareTo(a)==0)
            {
                System.out.println("YES");
            }
            else
            {
                System.out.println("NO");
            }
            
        }
    }
}

你可能感兴趣的:(BestCoder Round #64 (div.2) A Numbers&&HDU 5585)