hdu5050divided Land (Java large number)
Topic links
The main idea: to give you a long and wide rectangle, you need to divide the area into a plurality of side-length n square, there is no space left. Requires N to be as large as possible. Give you the binary length and width, and the output of n is also in binary form.
Solving ideas: Seeking L,m's gcd. However, because the input is a binary number is very large, just in the middle of the gcd when the time to go to decimal to obtain n, and output n is also a binary form.
Code:
Import Java.util.*;import Java.io.*;import java.math.*; Public classMain { Public StaticBigInteger GCD (BigInteger num1, BigInteger num2) {if(Num2.equals (Biginteger.zero))returnNUM1;returnGCD (num2, Num1.mod (num2)); } Public Static voidMain (String args[]) {ScannerCin=NewScanner (NewBufferedinputstream (system.in)); PrintWritercout=NewPrintWriter (NewBufferedoutputstream (System.out));intT T =Cin. Nextint (); BigInteger L, W; for(inti =1; I <= T; i++) {L =Cin. Nextbiginteger (2); W =Cin. Nextbiginteger (2); BigInteger ans = GCD (L, W);cout.printf("Case #%d:", i);cout. println (Ans.tostring (2)); }Cin. Close ();cout. Close (); }}
hdu5050divided Land (Java large number)