HDU 5832 A Water Problem "large number of models, Java large number is not omnipotent. 】

Source: Internet
Author: User

A Water problem Description

The planets named Haha and Xixi in the universe and they were created with the universe beginning.

There is the year of Xixi A and 137 days in Haha a.

Now you know the day N after Big Bang, you need to answer whether it's the first day of a year on about the the-the-same planets.

Input

There is several test cases (about 5 huge test cases).

For each test, we had a line with an only integer N (0≤n) and the length of n is up to 10000000.

Output

For the i-th test case, output case #i: And then output "YES" or "NO" for the answer.

Sample Input

10001
0
333

Sample Output

Case #1: YES
Case #2: YES
Case #3: NO

Topic Connection:

http://acm.hdu.edu.cn/showproblem.php?pid=5832

Test instructions

I'll give you a number and ask if you can divide the number by 137 and 73.

Exercises

These two number coprime, is actually asks you whether can divide 10001 (73*137,)

Just sweep it all over again.

Using string may be tle, so just use char.

Java is the MLE, it seems that Java is not omnipotent,

AC Code:

#include <iostream> #include <cstdio> #include <cstring>using namespace Std;char a[10000005];int Main () {    int kase=0;    int n;    Freopen ("Data/5832.txt", "R", stdin);    while (Cin>>a)    {        printf ("Case #%d:", ++kase);        int Len=strlen (a);        int mod=0;        for (int i=0;i<len;i++)        {            mod= (mod*10+a[i]-' 0 ')%10001;        }        if (mod==0)            cout<< "YES" <<endl;        else            cout<< "NO" <<endl;    }    return 0;}


Java MLE Code:

Import Java.math.biginteger;import Java.util.scanner;public class Main {public    static void Main (string[] args) {
   //TODO auto-generated Method stub        Scanner sc = new Scanner (system.in);        int kase = 0;        while (Sc.hasnext ()) {            BigInteger a = Sc.nextbiginteger ();            BigInteger mod = biginteger.valueof (10001);            BigInteger ans = a.mod (mod);            System.out.printf ("Case #%d:", ++kase);            if (Ans.equals (Biginteger.zero)) {                System.out.println ("YES");            } else{                System.out.println ("NO");}}}    



HDU 5832 A Water Problem "large number of models, Java large number is not omnipotent. 】

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.