请问为什么本蒟蒻这个题第二个点wa了
查看原帖
请问为什么本蒟蒻这个题第二个点wa了
754444
tamamocross楼主2022/11/13 17:02

另,这题一开o2优化就全re,不懂

#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
const int M=50001;
int prime[M],p[M],k=0;	
int a0,a1,b0,b1,t1=0,t2=0,t3=0,t4=0;
int P(){
	memset(p,0,sizeof(p));
	for(int i=2;i<M;i++){
		if(!p[i]){
			prime[++k]=i;
			for(int j=i;j<=M/i;j++){
				p[i]=1;
			}
		}
	}
}
void gcd(int n){
	while(a0%n==0){
		t1++;
		a0/=n;
	}
	while(a1%n==0){
		t2++;
		a1/=n;
	}
}
void lcm(int n){
	while(b0%n==0){
		t3++;
		b0/=n;
	}
	while(b1%n==0){
		t4++;
		b1/=n;
	}
}
long long pro(){
	long long ans=1;
	for(int i=1;i<=k;i++){
		t1=0,t2=0,t3=0,t4=0;
		if(b1%prime[i]==0){
		gcd(prime[i]);
		lcm(prime[i]);
		if(t2>t1||t2>t4){
			ans=0;
		}
		if(t1>t2&&t4>t3&&t2<t4){
			ans=0;
		}
		if(t1==t2&&t3==t4){
			ans*=(t4-t2+1);
		}	
	}
		if(ans==0){
			break;
		}
	}
	if(b1>1){
		t1=0,t2=0,t3=0,t4=0;
		gcd(b1);
		lcm(b1);
		if(t2>t1||t2>t4){
			ans=0;
		}
		if(t1>t2&&t4>t3&&t2<t4){
			ans=0;
		}
		if(t1==t2&&t3==t4){
			ans*=(t4-t2+1);
		}	
	}
	return ans;
}
int main(){
	P();
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a0>>a1>>b0>>b1;
		cout<<pro()<<endl;
	}
} 
2022/11/13 17:02
加载中...