/*
原式 b0*x/gcd(b0,x) = b1
-->b0*x = gcd(b0,x)*b1
-->b0*x/b1 = gcd(b0,x)
-->gcd(b0,x) = b0*x/b1
-->gcd(b1/x,b1/b0) = 1
gcd(x,a0)==a1
lcm(x,b0)==b1
//b1一定是x的整倍数,而x一定是a1的整倍数
*/
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=0;
bool f=0;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<0)
{
putchar('-'); x=-x;
}
if(x<10)
{
putchar(x+'0'); return;
}
write(x/10);
putchar((x%10)+'0');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=50005;
int a0,a1,b0,b1,ans;
bool Bo[N];
int Prim[N];
inline void Pre_Prime()
{
int i,j;
for(i=2;i<=50000;i++)
{
if(!Bo[i]) Prim[++*Prim]=i;
for(j=1;j<=*Prim&&Prim[j]*i<=50000;j++)
{
Bo[Prim[j]*i]=1;
if(i%Prim[j]==0) break;
}
}
return;
}
inline void Solve(int x)
{
int c0=0,c1=0,c2=0,c3=0;
while(a0%x==0){a0/=x; c0++;}
while(a1%x==0){a1/=x; c1++;}
while(b0%x==0){b0/=x; c2++;}
while(b1%x==0){b1/=x; c3++;}
if(c0<c1||c2>c3)
{
ans=0;
return;
}
if(c0==c1&&c2==c3)
{
if(c1<=c3) ans*=c3-c1+1;
else ans=0;
}
else if(c0>c1&&c2<c3&&c1!=c3)
{
ans=0;
}
return;
}
int main()
{
int i,T;
Pre_Prime();
R(T);
while(T--)
{
R(a0); R(a1); R(b0); R(b1);
ans=1;
for(i=1;i<=*Prim&&Prim[i]<b1&&ans;i++)
{
Solve(Prim[i]);
}
if(b1>1) Solve(b1);
Wl(ans);
}
return 0;
}
一本通1626:【例 2】Hankson 的趣味题
最新推荐文章于 2024-11-10 21:43:58 发布