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.

37 lines
811 B

2 years ago
#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 main() {
// 输入
int n;
cin >> n;
// 最大2000次噢
while (n--) {
/*
x a0 a1
x b0 b1
*/
int a0, a1, b0, b1;
cin >> a0 >> a1 >> b0 >> b1;
// 每次记数器清0
int cnt = 0;
// 枚举a1的所有倍数
for (int x = a1; x <= b1; x += a1)
if (gcd(x, a0) == a1 && lcm(x, b0) == b1) cnt++;
printf("%d\n", cnt);
}
return 0;
}