Java's large number calculation BigNumber

Source: Internet
Author: User

Notice that number 123456789 are a 9-digit number consisting exactly the numbers from 1 to 9, with no duplication. Double it we'll obtain 246913578, which happens to being another 9-digit number consisting exactly the numbers from 1 to 9, Only in a different permutation. Check to see the result if we double it again!

Now is suppose to check if there is more numbers with the This property. That's, double a given number with k digits, if the resulting number consists of only a permutation of th e digits in the original number.

Input Specification:

Each input file contains the one test case. Each case contains one positive integers with no more than digits.

Output Specification:

For each test case, first print in a line "Yes" if doubling the input number gives a number this consists of only a Permut Ation of the digits in the original number, or "No" if not. Then on the next line, print the doubled number.

Sample Input:
1234567899
Sample Output:
Yes2469135798
I don't know why there's a case like that.
1 ImportJava.math.BigInteger;2 ImportJava.util.Scanner;3 4  Public classA {5 6      Public Static voidMain (string[] args) {7Scanner cin =NewScanner (system.in);8BigInteger A =Cin.nextbiginteger ();9BigInteger BB =A;TenBigInteger C = biginteger.valueof (10); One BigInteger D; ABigInteger ans =A.add (BB); -BigInteger B =ans; -         BooleanBook =true; the         int[] Book0 =New int[10]; -          while(!a.equals (biginteger.valueof (0))) { - //System.out.println (a.equals (0)); -D =A.mod (c); +A =A.divide (c); -Book0[d.intvalue ()] = 1; +         } A          while(!b.equals (Biginteger.zero)) { atD =B.mod (c); -b =B.divide (c); -             if(Book0[d.intvalue ()]! = 1) { -Book =false; -                  Break; -             } in         } -         if(Book = =false) { toSystem.out.println ("No"); +         } -         Else { theSystem.out.println ("Yes"); *         } $ System.out.println (ans);Panax Notoginseng  -     } the  +}

Java's large number calculation BigNumber

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.