#include using namespace std; typedef long long LL; //TLE 5个点,50分 //最大公约数 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; //枚举a1的所有倍数 for (LL x = a1; x <= b1; x += a1) if (gcd(x, a0) == a1 && lcm(x, b0) == b1) cnt++; cout << cnt << endl; } return 0; }