Files
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

34 lines
1005 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
// 最大公约数
int gcd(int a, int b) {
return b ? gcd(b, a % b) : a;
}
// 最小公倍数
int lcm(int a, int b) {
return b / gcd(a, b) * a; // 注意顺序,防止乘法爆int
}
int main() {
int T;
cin >> T;
while (T--) {
int ans = 0, a0, a1, b0, b1;
cin >> a0 >> a1 >> b0 >> b1;
/*
读入四个数字
x 和 a0 的最大公约数是 a1
x 和 b0 的最小公倍数是 b1
*/
for (int i = 1; i * i <= b1; i++) { // 枚举b1的所有约数
if (b1 % i) continue; // 是因数
if (gcd(i, a0) == a1 && lcm(i, b0) == b1) ans++; // 因数i符合要求
int j = b1 / i; // 另一个因子
if (gcd(j, a0) == a1 && lcm(j, b0) == b1 && i != j) ans++;
}
printf("%d\n", ans);
}
return 0;
}