记录编号 531925 评测结果 AAAAAAAAAA
题目名称 [NOIP 2009]Hankson的趣味题 最终得分 100
用户昵称 Gravatar梦那边的美好ET 是否通过 通过
代码语言 C++ 运行时间 0.412 s
提交时间 2019-05-22 11:35:39 内存使用 1.77 MiB
显示代码纯文本
#include<bits/stdc++.h>
#define maxn 50010
using namespace std; 
int p[maxn],lp,bk[maxn];
inline void pre(){
	for(int i=2;i<=maxn-10;i++){
		if(bk[i]==0)p[++lp]=i;
		for(int j=1;j<=lp&&i*p[j]<=maxn-10;j++){
			bk[p[j]*i]=1;
			if(i%p[j]==0)break;
		}
	}
	return;
}
int T,a1,a2,a3,a4;
inline bool ju(int x){int h=sqrt(x);
	for(int i=1;i<=h;i++)if(x%i==0)return 0;
	return 1;
}
inline void insert(){
    freopen("son.in","r",stdin);        
    freopen("son.out","w",stdout);
    scanf("%d",&T);
	return;	
}
inline void work(){
	while(T--){
		scanf("%d%d%d%d",&a1,&a2,&a3,&a4);
		if(a1%a2!=0||a4%a3!=0){printf("0\n");continue;}
		int ans=1,w=0,n=sqrt(max(max(a1,a2),max(a3,a4)));
		for(int i=2;i<=n;i++){
			if(bk[i])continue;
			int s1=0,s2=0,s3=0,s4=0,l,r;
			while(a1%i==0)s1++,a1/=i;
			while(a2%i==0)s2++,a2/=i;
			while(a3%i==0)s3++,a3/=i;
			while(a4%i==0)s4++,a4/=i;
			if(s2>s4){w=1;break;}
			if(s1!=s2&&s3!=s4&&s2!=s4){w=1;break;}
			if(s1!=s2&&max(s2,s3)!=s4){w=1;break;}
			if(s3!=s4&&min(s1,s4)!=s2){w=1;break;}
			if(s1==s2&&s3==s4)ans*=(s4-s2+1);
		}
		int p=max(a1,a2);
		if(p!=1){
        	int s1=0,s2=0,s3=0,s4=0,l,r,i=p;
			while(a1%i==0)s1++,a1/=i;
			while(a2%i==0)s2++,a2/=i;
			while(a3%i==0)s3++,a3/=i;
			while(a4%i==0)s4++,a4/=i;
			if(s2>s4){printf("0\n");continue;}
			if(s1!=s2&&s3!=s4&&s2!=s4){printf("0\n");continue;}
			if(s1!=s2&&max(s2,s3)!=s4){printf("0\n");continue;}
			if(s3!=s4&&min(s1,s4)!=s2){printf("0\n");continue;}
			if(s1==s2&&s3==s4)ans*=(s4-s2+1);
		}p=max(a3,a4);
		if(p!=1){
        	int s1=0,s2=0,s3=0,s4=0,l,r,i=p;
			while(a1%i==0)s1++,a1/=i;
			while(a2%i==0)s2++,a2/=i;
			while(a3%i==0)s3++,a3/=i;
			while(a4%i==0)s4++,a4/=i;
			if(s2>s4){printf("0\n");continue;}
			if(s1!=s2&&s3!=s4&&s2!=s4){printf("0\n");continue;}
			if(s1!=s2&&max(s2,s3)!=s4){printf("0\n");continue;}
			if(s3!=s4&&min(s1,s4)!=s2){printf("0\n");continue;}
			if(s1==s2&&s3==s4)ans*=(s4-s2+1);
		}
		if(w)printf("0\n");
		else printf("%d\n",ans);
	}
	return;
}
inline int MAIN(){ 
    pre();
    insert();
    work();
    return 0;  
}
int hs=MAIN();
int main(){;}