[Bnuz oj]1176 and Square

Source: Internet
Author: User

Portal

Description of the problem one day, the ACM's Anxiaoqiu got a very big big piece of paper. He is now going to tear it into a square. But he doesn't have any tools, no rulers, so he tries an interesting way to slice the rectangle. Suppose this is a a*b rectangle (a>b), then the little will be a corner of the rectangle fold, so that the right side will form a square, and then cut out the square, if there is still a rectangle, Anxiaoqiu will continue to cut the square out, now ask you to write programs, output Anxiaoqiu so that eventually can How many squares to get.
Input requires more than one set of input data.
Each test data is a row, there are two integers a, b, respectively, represents the length and width of the paper that the 1≤ b< a≤10^12) output requires output, and the output takes up one row. Test Data Sample Input 2 1
10 7 Output 2
6 Today, I did a new school problem, I think it is quite fun. There are some geometrical problems that need to be optimized, and the violence will be tle. First, if B is a factor, that is, A%b ==0, then, it is not difficult to think, you can know the number of squares generated in the current situation A/b. So when a%b!=0, that means to lose a part of the square, and then Judge A%b==0, It's OK. On the Code
#include <stdio.h>Long LongSlove (Long LongALong Longb) {    Long LongRET =0;  while(a!=b) {      if(a<b) {         intt =b; b=FA; A=T; }        if(a%b==0){            returnRet+ (A/b); }Else{ret+=a/b; A=a-(b* (A/b)); }    }    if(a==b) ret++; returnret;}intMain () {Long Longb;  while(SCANF ("%lld%lld", &a,&b) = =2) {printf ("%lld\n", Slove (A, b)); }    return 0;}

[Bnuz oj]1176 and Square

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.