Java large number practice first play

Source: Internet
Author: User

Today to more than a large number of Java brush, to fight for the easy water after the large number of problems ~


HDU 1002 Large number Add Link: http://acm.hdu.edu.cn/showproblem.php?pid=1002

Code

Import Java.util.*;import Java.math.biginteger;public class main{public    static void Main (string[] args) {        Scanner in=new Scanner (system.in);        int N=in.nextint ();        for (int i=1;i<=n;i++) {            BigInteger a,b,c;            A=in.nextbiginteger ();            B=in.nextbiginteger ();            C=a.add (b);            if (i!=1)                System.out.println ();            SYSTEM.OUT.PRINTLN ("Case" +i+ ":");            System.out.println (A + "+" +b+ "=" +c);}}}    

HDU 1042 Large number of factorial links: http://acm.hdu.edu.cn/showproblem.php?pid=1042

Code


Import Java.util.*;import Java.math.biginteger;public class main{public    static void Main (string[] args) {        Scanner in=new Scanner (system.in);                int A;        while (In.hasnext ()) {            a=in.nextint ();            BigInteger Ans=biginteger.one;                    for (int i=1;i<=a;i++) {                ans=ans.multiply (biginteger.valueof (i));            }            System.out.println (ANS);}}    

HDU 1133 The application of the number of Rand Links: http://acm.hdu.edu.cn/showproblem.php?pid=1133


Code

Mport Java.util.*;import Java.math.biginteger;public class main{public    static void Main (string[] args) {            int A, b;            Scanner in=new Scanner (system.in);            int cnt=0;            while (In.hasnext ()) {                cnt++;                A=in.nextint ();                B=in.nextint ();                BigInteger Ans=biginteger.one;                if (a==0&&b==0) break;                if (a<b) Ans=biginteger.zero;                else {for                    (int i=1;i<=a+b;i++) {                        ans=ans.multiply (biginteger.valueof (i));                    }                    int mpl= (a-b+1);                    int dvd= (a+1);                    Ans=ans.multiply (biginteger.valueof (MPL));                    Ans=ans.divide (biginteger.valueof (DVD));                }                System.out.println ("Test #" +cnt+ ":");                System.out.println (ANS);}}        



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java large number practice first play

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.