HUD 5050 divided land

Source: Internet
Author: User

 

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

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.