Solution ((90\%))
注意到(operatorname{lcm}(b_0,x) = b_1),所以(x mid b_1),枚举(b_1)的所有约数并暴力计算。
时间复杂度(mathcal{O}(n sqrt{b_1} log{b_1}))
Solution ((100\%))
枚举质数(p mid d_1),令(m_1)为(a_0)中包含(p)因子的个数,(m_2,m_3,m_4)同理。
进行分类讨论。
# include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n;
int ans = 1;
int a0,a1,b0,b1;
template <typename T> void read(T &x)
{
int w = 1;
x = 0;
char ch = getchar();
while(!isdigit(ch))
{
if(ch == '-') w = -1;
ch = getchar();
}
while(isdigit(ch))
{
x = x * 10 + ch - '0';
ch = getchar();
}
x *= w;
return;
}
void solve(int p)
{
int m1 = 0,m2 = 0,m3 = 0,m4 = 0;
while(a0 % p == 0)
{
a0 /= p;
++m1;
}
while(a1 % p == 0)
{
a1 /= p;
++m2;
}
while(b0 % p == 0)
{
b0 /= p;
++m3;
}
while(b1 % p == 0)
{
b1 /= p;
++m4;
}
// printf("p = %d,m1 = %d,m2 = %d,m3 = %d,m4 = %d
",p,m1,m2,m3,m4);
if(m1 > m2 && m3 < m4)
{
if(m2 != m4) ans = 0;
}
else if(m1 > m2 && m3 == m4)
{
if(m2 > m4) ans = 0;
}
else if(m1 == m2 && m3 < m4)
{
if(m2 > m4) ans = 0;
}
else if(m1 == m2 && m3 == m4)
{
if(m2 > m4) ans = 0;
else ans *= (m4 - m2 + 1);
}
else ans = 0;
return;
}
int v[N],prime[N],tot;
void Get_prime(int n)
{
for(int i = 2; i <= n; i++)
{
if(v[i] == 0)
{
v[i] = i;
prime[++tot] = i;
}
for(int j = 1; j <= tot && prime[j] * i <= n; j++)
{
if(prime[j] > v[i]) break;
v[prime[j] * i] = prime[j];
}
}
return;
}
int main(void)
{
read(n);
Get_prime(50000);
int _b1 = b1;
while(n--)
{
ans = 1;
read(a0),read(a1),read(b0),read(b1);
for(int i = 1; i <= tot; i++)
{
if(_b1 % prime[i] == 0) solve(prime[i]);
else break;
if(ans == 0) break;
}
if(b1 != 1) solve(b1);
printf("%d
",ans);
}
return 0;
}