hdu5050divided Land (Java large number)

Source: Internet
Author: User
Tags gcd

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)

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.