You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.1 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
/**
3 60
4
*/
//最大公约数
LL gcd(LL x, LL y) {
return y ? gcd(y, x % y) : x;
}
//最小公倍数
int lcm(int x, int y) {
return y / gcd(x, y) * x; //注意顺序防止乘法爆int
}
int cnt;
LL x; //最大公约数
LL y; //最小公倍数
int main() {
cin >> x >> y;
//理论依据gcd(p,q)*lcm(p,q)=p*q
//枚举最小公倍数y的约数,这个约数可能是p,也可能是y/p
for (LL k = 1; k * k <= y; k++)
if (y % k == 0) {
//可能小因子是p也可能大因子是p,但大小因子别一样,那样会算重了。
LL p = k;
LL q = x * y / k; //q是靠计算出来的。q=x*y/p
if (gcd(p, q) == x) cnt++;
//p=y/k,q=x*y/(y/k)=k*x 两组不能重复,就是 y/k!=k
if (k == y / k)continue;
//p是大因子的可能性
p = y / k;
q = k * x;
if (gcd(p, q) == x) cnt++;
}
cout << cnt << endl;
return 0;
}