枚举gcd(x,b0)判断
1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<cstring> 5 #include<cmath> 6 #include<stack> 7 #include<algorithm> 8 using namespace std; 9 #define ll long long 10 #define rg register 11 const int N=2000+5,M=2000000000+5,X=4000; 12 template <class t>void rd(t &x) 13 { 14 x=0;int w=0;char ch=0; 15 while(!isdigit(ch)) w|=ch==‘-‘,ch=getchar(); 16 while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar(); 17 x=w?-x:x; 18 } 19 20 int gcd(int a,int b){return b?gcd(b,a%b):a;} 21 22 int main() 23 { 24 //freopen("in.txt","r",stdin); 25 //freopen("nocows.out","w",stdout); 26 int T;rd(T); 27 while(T--) 28 { 29 int a0,a1,b0,b1,ans=0,lim,x; 30 rd(a0),rd(a1),rd(b0),rd(b1); 31 if(b1%b0) {printf("0\n");continue;} 32 for(rg int i=1;i<sqrt(b0);++i) 33 { 34 if(b0%i) continue; 35 x=b1/b0*i; 36 if(gcd(x,b0)==i&&gcd(x,a0)==a1) ++ans; 37 x=b1/b0*(b0/i); 38 if(gcd(x,b0)==b0/i&&gcd(x,a0)==a1) ++ans; 39 } 40 lim=int(sqrt(b0)); 41 if(lim*lim==b0&&!(b1%lim)) 42 { 43 x=b1/b0*lim; 44 if(gcd(x,b0)==lim&&gcd(x,a0)==a1) ++ans; 45 } 46 printf("%d\n",ans); 47 } 48 return 0; 49 }
原文地址:https://www.cnblogs.com/lxyyyy/p/10879421.html
时间: 2024-10-09 20:27:01