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.

45 lines
1.5 KiB

2 years ago
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
//最大公约数
LL gcd(LL x, LL y) {
return y ? gcd(y, x % y) : x;
}
//最小公倍数
LL lcm(LL x, LL y) {
return y / gcd(x, y) * x; //注意顺序防止乘法爆int
}
int main() {
//输入
int n;
cin >> n;
//最大2000次噢
while (n--) {
//读入四个数字
LL a0, a1, b0, b1;
cin >> a0 >> a1 >> b0 >> b1;
//每次记数器清0
int cnt = 0;
//平方根法
//思路:遍历所有最小公倍数的因子,找到最小公倍数的小因子,判断它是不是符合条件,再判断大因子是不是也符合条件即可。
//注意小因子和大因子需要不一样大,否则就只记录一个就行。
//枚举b1的所有小因子(枚举b1的约数)
//for (LL x = 1; x <= sqrt(b1); x++) {
for (LL x = 1; x * x <= b1; x++) { // 优化后写成x*x 的表示方法。
if (b1 % x == 0) {
//现在x是b1的小因子是否符合题意要求呢
if (gcd(x, a0) == a1 && lcm(x, b0) == b1) cnt++;
// 与x相对的大因子,这里需要特判如果b1是一个完全平方数那么小因子、大因子是一样的记录一个就行。
if (b1 / x != x)
if (gcd(b1 / x, a0) == a1 && lcm(b1 / x, b0) == b1)cnt++;
}
}
cout << cnt << endl;
}
return 0;
}