Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 5050
Question:
Given the length and width of a rectangle, this rectangle is divided into several equal squares with no surplus. The maximum length of the side of the square.
Solution:
This is a variant of the "Pick Theorem" (I don't know it's the pick theorem, But I can leave the conclusion ). The theorem is used to obtain the length and width of a rectangle. However, the input number is binary,
The output is also binary, and the size of the binary is 2 ^ 1000, so it is a large number algorithm. JAVA supports processing large numbers.
1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 5 public class Main { 6 public static void main(String[] args) { 7 Scanner cin = new Scanner(System.in); 8 9 int t = cin.nextInt();10 for(int cs = 1; cs <= t; ++cs){11 BigInteger a = cin.nextBigInteger(2);12 BigInteger b = cin.nextBigInteger(2);13 System.out.println("Case #"+cs+": "+a.gcd(b).toString(2));14 }15 16 cin.close();17 }18 }
HUD 5050 divided land