結果
| 問題 |
No.577 Prime Powerful Numbers
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-14 18:52:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,112 bytes |
| コンパイル時間 | 315 ms |
| コンパイル使用メモリ | 40,448 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 18:44:46 |
| 合計ジャッジ時間 | 804 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 1 WA * 9 |
ソースコード
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
typedef unsigned long long ull;
typedef unsigned long long val_t;
ull gcd(ull x,ull y){return y?gcd(y,x%y):x;}
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;
y>>=1;
}
return z;
}
bool miller_rabin(val_t n){
if(n==2)return true;
if(n==1||n%2==0)return false;
val_t 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
val_t 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;
}
ull p0(ull n,ull k){
ull r=1;
for(;k--;r*=n);
return r;
}
ull p1(ull n,ull t){
ull r=1,i=0;
for(;r<=t;r*=n)i++;
return i;
}
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:exp(log(n+1)/k)+1e-6;
if(m+p0(r,k)!=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);
}