HDU 2504 又见GCD (最大公因数+暴力)

题意:是中文题。

析:a和c的最大公因数是b,也就是说,a和c除了b就没有公因数了。再说就是互质了。

所以先把a除以b,然后一个暴力n,满足gcd(a, n) =1,就结束,就是n倍的c。

代码如下:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <cstring>
#include <map>
#include <cctype>
#include <cmath>

using namespace std;
typedef long long LL;
const int maxn = 1000000;
int a[maxn];

int gcd(int a, int b){  return b == 0 ? a : gcd(b, a%b);  }

int main(){
    int T, a, b;  cin >> T;
    while(T--){
        scanf("%d %d", &a, &b);
        a /= b;
        for(int i = 2; ; ++i)
            if(1 == gcd(i, a)) { printf("%d
", b * i);  break;  }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/dwtfukgv/p/5557838.html