欧几里得算法用来求最大公约数
int gcd(int a, int b)
{
if(b == 0) return a;
else return gcd(b, a % b);
}
例题:洛谷p1029
#include<iostream>
using namespace std;
#define int long long
#define endl '\n'
int x, y;
int ans;
int gcd(int x, int y)
{
if(y == 0) return x;
else return gcd(y, x % y);
}
signed main()
{
ios :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> x >> y;
int t = x * y;
for(int i = 1; i * i <= t; i ++ ) //i代表p,枚举p,因为pq=xy,所以q=t/i
if(t % i == 0 && gcd(i, t / i) == x)
ans += 2;
if(x == y) ans -- ;
cout << ans;
return 0;
}