传送门:https://www.luogu.org/problemnew/show/P1072
啊,辣鸡数论题qnq
又题意可得:
gcd(x,a0)=a1->gcd(x/a1,a0/a1)=1
lcm(x,b0)=b1->gcd(x,bo)=x*b0/b1->gcd(b1/x,b1/b0)=1
然后我们可以显而易见得得到的是x是a1的倍数且是b1的因子,然后就sqrt(n)次暴力枚举b1的因子判断就好啦qwq
code:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <ctime>
using namespace std;
int n,ans,a0,a1,b0,b1;
int read()
{
int xx=0,kk=1;char ch=' ';
while(!isdigit(ch)){ch=getchar();if(ch=='-')kk=-1;}
while(isdigit(ch)){xx=xx*10+ch-'0';ch=getchar();}
return kk*xx;
}
int gcd(int a,int b)
{
return b?gcd(b,a%b):a;
}
int main()
{
n=read();
while(n--)
{
ans=0;
a0=read(),a1=read(),b0=read(),b1=read();
for(int i=1;i*i<=b1;++i)
{
if(b1%i) continue;
int j=b1/i;
if(!(i%a1)&&gcd(i/a1,a0/a1)==1&&gcd(b1/i,b1/b0)==1) ans++;
if(!(j%a1)&&gcd(j/a1,a0/a1)==1&&gcd(b1/j,b1/b0)==1&&i!=j) ans++;
}
printf("%d\n",ans);
}
}