http://acm.hdu.edu.cn/showproblem.php?pid=5640

这题有点辗转相除的意思。基本没有什么坑点。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <string>
#define LL long long

using namespace std;

int n, m;

int main()
{
    //freopen("test.in", "r", stdin);
    int T;
    scanf("%d", &T);
    for (int times = 1; times <= T; ++times)
    {
        scanf("%d%d", &n, &m);
        int ans = 0;
        while (n&&m)
        {
            if (n > m) swap(n, m);
            ans += m/n;
            m = m%n;
        }
        printf("%d\n", ans);
    }
    return 0;
}
View Code

相关文章: