CF527A:Playing with Paper——题解

https://vjudge.net/problem/CodeForces-527A

http://codeforces.com/problemset/problem/527/A

题目大意:一个纸长a,宽b。每次我们切下来最大的正方形直到剩下的纸也为正方形即停。求正方形个数。

——————————

更相减损之术的次数,用辗转相除法优化即可。

#include<cstdio>  
#include<cstring>  
#include<cstdlib>  
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll cnt=0;
ll gcd(ll a,ll b){
    if(!b)return a;
    cnt+=a/b;
    return gcd(b,a%b);
}
int main(){
    ll a,b;
    scanf("%lld%lld",&a,&b);
    gcd(a,b);
    printf("%lld
",cnt);
    return 0;
}
原文地址:https://www.cnblogs.com/luyouqi233/p/7921216.html