結果

問題 No.577 Prime Powerful Numbers
ユーザー cielciel
提出日時 2017-10-14 19:07:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 971 bytes
コンパイル時間 362 ms
コンパイル使用メモリ 40,704 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 22:07:19
合計ジャッジ時間 1,282 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 25 ms
5,376 KB
testcase_04 AC 7 ms
5,376 KB
testcase_05 AC 125 ms
5,376 KB
testcase_06 AC 10 ms
5,376 KB
testcase_07 AC 124 ms
5,376 KB
testcase_08 AC 22 ms
5,376 KB
testcase_09 AC 21 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef unsigned long long ull;
typedef __uint128_t val_t;

val_t po(val_t x,val_t y,val_t m){
	val_t z=1;
	for(;y;y>>=1){
		if(y&1)z=z*x%m;
		x=x*x%m;
	}
	return z;
}

ull gcd(ull x,ull y){return y?gcd(y,x%y):x;}
bool miller_rabin(ull n){
	if(n==2)return true;
	if(n==1||n%2==0)return false;
	ull d=n-1,s=0,a=1;
	for(;d%2==0;d/=2)s+=1;
	for(int k=5;k--;){ //todo
		for(a++;gcd(a,n)!=1;a++); //todo
		ull r=po(a,d,n);
		if(r==1||r==n-1)continue;
		int t=s;
		for(;t;t--){
			r=po(r,2,n);
			if(r==n-1)break;
		}
		if(!t)return false;
	}
	return true;
}

void solve(ull n){
	if(n%2==0){puts(n>2?"Yes":"No");return;}
	for(ull m=2;m<n;m*=2){
		ull z=n-m;
		for(int k=1;k<61;k++){
			ull r=k==1?z:expl(logl(n+1)/k)+1e-6;
			if(m+po(r,k,1LL<<62)!=n)continue;
			if(miller_rabin(r)){puts("Yes");return;}
		}
	}
	puts("No");
}
int main(){
	ull t,n;
	for(scanf("%llu",&t);t--;solve(n))scanf("%llu",&n);
}
0