Today, I suddenly saw the big number questions on OJ, because I learned a little big number knowledge. Decisive 6 questions ...... Is very basic. It's just a matter of practice.
What I learned is only the basic operations of some big data classes. I will do more such questions in the future, and strive to be proficient in using big data questions...
Big Data factorial
Question link: http://acm.nyist.net/JudgeOnline/problem.php? PID = 28
The Code is as follows:
import java.io.*;import java.math.BigInteger;import java.util.*;public class Main{public static void main(String args[]){Scanner cin = new Scanner(System.in);int n = cin.nextInt();BigInteger ans = BigInteger.ONE;for(int i = 1; i <= n; ++i)ans = ans.multiply(BigInteger.valueOf(i));System.out.println(ans);}}
Board coverage
Question link: http://acm.nyist.net/JudgeOnline/problem.php? PID = 45
The Code is as follows:
import java.math.BigInteger;import java.util.*;import java.io.*;public class Main{public static void main(String args[]){Scanner in = new Scanner(System.in);int test = in.nextInt();while(test-- > 0){int n;n = in.nextInt();BigInteger a = new BigInteger("4");for(int i = 1; i < n; ++i)a = a.multiply(BigInteger.valueOf(4));System.out.println(a.subtract(BigInteger.valueOf(1)).divide(BigInteger.valueOf(3)));}}}
Compare size
Question link: http://acm.nyist.net/JudgeOnline/problem.php? PID = 73
The Code is as follows:
import java.io.*;import java.math.BigInteger;import java.util.*;public class Main{public static void main(String args[]){Scanner cin = new Scanner(System.in);while(cin.hasNext()){BigInteger a = cin.nextBigInteger();BigInteger b = cin.nextBigInteger();if(a.equals(BigInteger.ZERO) && b.equals(BigInteger.ZERO))break;int flag = a.compareTo(b);if(flag == -1)System.out.println("a<b");else if(flag == 0)System.out.println("a==b");elseSystem.out.println("a>b");}}}
Addition of large numbers
Question link: http://acm.nyist.net/JudgeOnline/problem.php? PID = 1, 103
The Code is as follows:
import java.math.BigInteger;import java.util.*;import java.io.*;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 = in.nextBigInteger();BigInteger b = in.nextBigInteger();BigInteger ans = a.add(b);System.out.println("Case " + i + ":");System.out.println(a + " + " + b + " = " +ans);}}}
Recursive Evaluation
Question link: http://acm.nyist.net/JudgeOnline/problem.php? PID = 1, 114
The Code is as follows:
import java.io.*;import java.math.BigInteger;import java.util.*;public class Main{public static void main(String args[]){Scanner cin = new Scanner(System.in);BigInteger a[] = new BigInteger[100];while(cin.hasNext()){for(int i = 0; i <= 2; ++i)a[i] = cin.nextBigInteger();for(int i = 3; i <= 99; ++i)a[i] = a[i - 1].add(a[i - 2]).add(a[i - 3]);System.out.println(a[99]);}}}
High Precision power
Question link: http://acm.nyist.net/JudgeOnline/problem.php? PID = 1, 155
The Code is as follows:
Import Java. io. *; import Java. math. bigdecimal; import Java. util. *; public class main {public static void main (string ARGs []) {program CIN = new program (system. in); While (CIN. hasnext () {bigdecimal ans = cin. nextbigdecimal (); int n = cin. nextint (); string res = ans. pow (n ). striptrailingzeros (). toplainstring (); // The integer removes the decimal point and the 0if (res. startswith ("0") // remove the leading 0 {res = res. substring (1);} system. out. println (RES );}}}