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.

34 lines
1005 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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;
}