Acm hdu tiles of RIS, not! (Simple question)

Source: Internet
Author: User
Tiles of Tetris, not!

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 569 accepted submission (s): 229

Problem descriptionyou 've really messed up this time. "Go buy some square tiles" your supervisor told you. but as usual, you were either busy reading that message, answering that e-email, or updating your wall status on Facebook. "Go buy some tiles" was all that you coshould remember. your supervisor is now complaining that the tiles you bought were not squares and you'll be fired if you don't fix it!
"Fix it? How am I supposed to fix it ?" You say to yourself. "I'm a programmer, the only tiles I know are those of the game RIS !" There is no way you can afford to be fired either. This is your third job in less than a month. "I have to fix it !" You keep repeating.
You call the store you bought the tiles from, but they won't take them back or even exchange. "We cannot cancel orders once the merchandise has left the store", they tell you. you take a look at the tiles, they're all rectangleshaped and all of the same size. you 'd be losing a lot if you cut them, not that you 'd be able to cut them into perfect squares in the first place. "Wait a minute!" You say to yourself. You grab a bunch of tiles, put them in some arrangement and voila, that's a square. But that won't convince your boss.
Tiles are supposed to be small, and what you came-up with is rather big. you take another look at your arrangement, and it hits you again. "I'm on a roll today!" You say proudly to yourself. You just figured out how to find the smallest number of tiles needed to form the smallest possible square.

You rush and bring your supervisor to show him your discovery. he's not that much impressed. you're not making sense anyway (given all the blood rushing in your head trying to explain your algorithm .) you know that the calculation is definitely much simpler than what you're saying, but you just can't seem to think clearly.
Finally, your supervisor shouts: "First of all, the tiles have to be laid-down in the same orientation. Second, I'm running a construction site here, not a software shop! How do you know the workers to figure out that number! You either write me a program to do the calculation you're describing, or you go collect your netbook, your cell, your iPod, and your BlackBerry, and you get out of here this minute!"

Inputyour program will be tested on one or more data sets. each test set is described on a single line made of two positive numbers: (0 <W, H <1,000,000) which are the width and height of each tile. the last line is made of two zeros.

Outputfor each test case, write the answer on a separate line.

Sample input2 3
1 2
0 0

Sample output6
2

Source2009 anarc

Recommendlcy
 # Include  <  Stdio. h  >  
Int Gcd ( Int A, Int B)
{
Int C;
If ( = 0 ) Return B;
While (B ! = 0 ) C = B, B = A % B, = C;
Return A;
}
Int Main ()
{
Int A, B;
While (Scanf ( " % D " , & A, & B ))
{
If ( = 0 && B = 0 ) Break ;
Int C = Gcd (A, B );
Long Long D = ( Long Long ) * B / C / C;
Printf ( " % I64d \ n " , D );
}
Return 0 ;
}

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.