既然a跟b的最小公倍数是y,那就是说a跟b都是y的约数
这样我们可以先把y的所有约数找到然后直接两重循环枚举约数检验是否满足条件即可
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long LL;
vector<LL> v;
LL gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int main()
{
int x, y, res = 0;
scanf("%d%d", &x, &y);
for (int i = 1; i <= y; i ++ ) if (y % i == 0) v.push_back(i);
for (int i = 0; i < v.size(); i ++ )
{
for (int j = 0; j < v.size(); j ++ )
{
int g = gcd(v[i], v[j]);
if (g == x && v[i] * v[j] / g == y) res ++ ;
}
}
cout << res << endl;
return 0;
}
incredible