36 lines
669 B
C++
36 lines
669 B
C++
|
|
#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
|
|||
|
|
//枚举最大公约数x的倍数
|
|||
|
|
for (LL p = x; p <= y; p += x) {
|
|||
|
|
LL q = x * y / p;
|
|||
|
|
if (gcd(p, q) == x && lcm(p, q) == y) cnt++;
|
|||
|
|
}
|
|||
|
|
cout << cnt << endl;
|
|||
|
|
return 0;
|
|||
|
|
}
|