#include <iostream>
using namespace std;
int gcd(int x, int y) {
if (y == 0) return x;
return gcd(y, x % y);
}
int ans;
int main() {
int p, q;
cin >> p >> q;
for (int i = 1; i <= q; i++) {
for (int j = i; j <= q; j++) {
int g = gcd(i, j);
if (g == p && (i / g * j) == q) {
if (i != j) ans += 2;
else ans++;
}
}
}
cout << ans;
return 0;
}
除了枚举想不到别的办法了,有其他算法或者可以对我当前代码进行优化吗?谢谢
TLE on #6,#7,#8,#10