結果

問題 No.577 Prime Powerful Numbers
ユーザー CZS_AK_IOI2025
提出日時 2025-04-27 21:58:58
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,309 bytes
コンパイル時間 2,055 ms
コンパイル使用メモリ 196,732 KB
実行使用メモリ 25,524 KB
最終ジャッジ日時 2025-04-27 21:59:09
合計ジャッジ時間 11,279 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7 WA * 1 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int __int128
namespace CZS_Office{
	inline int read(){
		int x=0,f=1;
		char ch=getchar();
		while(ch<'0'||ch>'9'){
			if(ch=='-')f=-1;
			ch=getchar();
		}
		while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
		return x*f;
	}
	inline void write(int x){
		if(x<0){
			putchar('-');
			x=-x;
		}
		if(x>9)write(x/10);
		putchar(x%10+'0');
		return;
	}
	inline int ksm(int d,int z){
		int res=1;
		while(z){
			if(z&1){
				if(d*res>1e18)return 2e18;
				res*=d;
			}
			if(d*d>1e18)d=2e18;
			d*=d;z>>=1;
		}
		return res;
	}
	inline int shr(int d,int z,int p){
		int res=1;
		while(z){
			if(z&1){
				(res*=d)%=p;
			}
			(d*=d)%=p;z>>=1;
		}
		return res;
	}
}
using namespace std;
using namespace CZS_Office;
const __int128 ONE = 1;mt19937 rnd(time(0));
bool millerRabin(int n) 
{
	if (n < 3 || n % 2 == 0) return n == 2;
	int a = n - 1 , b = 0 , tt = 11;
	while (a % 2 == 0) a /= 2 , ++ b;
	for(int i = 1 ; i <= tt ; i ++)
	{
		int x = 1 * rnd() * rnd() % (n - 2) + 2 , v = shr(x , a , n);
		if (v == 1) continue;int j;
		for(j = 1 ; j <= b ; j ++) 
		{
			if (v == n - 1) break;
			v = (int)v * v % n;
		}
		if (j > b) return 0;
	}
	return 1;
}
int prime[6000005],prcnt;
bool isp[10000005],isCZS[10000005];
inline void init(){
	for(int i=2;i<=10000000;++i){
		if(!isp[i])prime[++prcnt]=i;
		for(int j=1;j<=prcnt&&prime[j]*i<=10000000;++j){
			isp[prime[j]*i]=1;
			if(i%prime[j]==0)break;
		}
	}
	return;
}

inline bool Isp(int res){
	return millerRabin(res);
	if(res<2)return 0;
	if(res<=10000000)return !isp[res];
	int T=3;
	while(T--){
		int x=rnd()%(res-1)+1;
		if(shr(x,res-1,res)!=1)return 0;
	}
	return 1;
}
inline int czs(int x,int z){
	int L=1,R=x;
	while(L<=R){
		int mid=(L+R)>>1;
		int res=ksm(mid,z);
		if(res==x)return Isp(mid);
		if(res>x)R=mid-1;
		else L=mid+1;
	}
	return 0;
}
inline bool chk(int x){
	for(int i=1;i<=60;++i)
		if(czs(x,i))return 1;
	return 0;
}
inline bool liliang(int x){
	if(x%2==0){
		if(x>=4)return 1;
		else return 0;
	}
	else{
		for(int i=2,j=1;i<=x&&j<60;++j,i*=2){
			if(chk(x-i))return 1;
		}
		return 0;
	}
	return 0;
}
signed main(){
//	freopen("number.in","r",stdin);
//	freopen("number.out","w",stdout);
	int Q=read();init();
	while(Q--){
		int n=read();
		if(liliang(n))cout<<"Yes\n";
		else cout<<"No\n";
	}
	return 0;
}
0