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.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
//最大公约数
|
|
|
|
|
int gcd(int x, int y) {
|
|
|
|
|
return y ? gcd(y, x % y) : x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//最小公倍数
|
|
|
|
|
int lcm(int x, int y) {
|
|
|
|
|
return y / gcd(x, y) * x; //注意顺序,防止乘法爆int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int cnt;
|
|
|
|
|
int x; //最大公约数
|
|
|
|
|
int y; //最小公倍数
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
//利用性质4:gcd(p,q)*lcm(p,q)=p*q
|
|
|
|
|
//可以减少一维循环
|
|
|
|
|
cin >> x >> y;
|
|
|
|
|
for (int p = x; p <= y; p++) { //穷举进化法
|
|
|
|
|
int q = x * y / p; //已知p,通过性质最大公约*最小公倍=两个数的乘积,
|
|
|
|
|
// 可以计算出另一个数字,这样,就可以去掉一层循环,效率明显提升。
|
|
|
|
|
// 应该满足如下的要求
|
|
|
|
|
if (gcd(p, q) == x && lcm(p, q) == y) cnt++;
|
|
|
|
|
}
|
|
|
|
|
cout << cnt << endl;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|