原题链接
题目分析如图:
代码如下:
#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y)
{
while (y ^= x ^= y ^= x %= y);
//正常求gcd(x,y)即可,不要这样写
return x;
}
int main()
{
int t;
ios::sync_with_stdio(false);
cin >> t;
int a0, a1, b0, b1;
int maxx;
while (t--)
{
cin >> a0 >> a1 >> b0 >> b1;
int cnt = 0;
int p = a0 / a1, q = b1 / b0;
for (int i = 1; i * i <= b1; i++)
{
if (b1 % i == 0)
{
if (i % a1 == 0 && gcd(p, i / a1) == 1 && gcd(q, b1 / i) == 1)
{
cnt++;
}
int y = b1 / i;
if (i == y)
continue;
if (y % a1 == 0 && gcd(p, y / a1) == 1 && gcd(q, b1 / y) == 1)
cnt++;
}
}
cout << cnt << endl;
}
return 0;
}