結果
| 問題 |
No.577 Prime Powerful Numbers
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-13 23:30:54 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,401 bytes |
| コンパイル時間 | 1,464 ms |
| コンパイル使用メモリ | 159,076 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 18:14:05 |
| 合計ジャッジ時間 | 4,354 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 WA * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:64:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
64 | scanf("%d",&q);
| ~~~~~^~~~~~~~~
main.cpp:67:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
67 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
std::random_device rd;
ll mod_pow(ll x,ll n,ll mod){
ll res=1;
x%=mod;
while(n>0){
if(n&1)res=res*x%mod;
x=x*x%mod;
n>>=1;
}
return res;
}
ll calc(ll v,ll tgt,int po){
ll ans=1;
for(int i=0;i<po;i++){
ans*=v;
}
return (ans==tgt);
}
bool is_prime(ll val){
if(val==1LL)return false;
for(int i=0;i<10000;i++){
ll v=rd()%val;
if(v==0)v=1;
if(mod_pow(v,val-1LL,val)!=1LL)return false;
}
return true;
}
bool C(ll v,ll tgt,int po){
ll res=1;
for(int i=0;i<po;i++){
if((tgt+v)/v<res)return false;
res*=v;
}
return res<=tgt;
}
bool check(ll val,int po){
if(po==1)return is_prime(val);
else{
ll l=1,r=1e9;
while(l+1<r){
ll mid=(l+r)/2LL;
if(C(mid,val,po))l=mid;
else r=mid;
}
//printf("%lld %lld %d\n",l,val,po);
if(calc(l,val,po) && is_prime(l))return true;
else return false;
}
}
int main(void){
srand((unsigned)time(NULL));
int q;
scanf("%d",&q);
for(int i=0;i<q;i++){
ll n;
scanf("%lld",&n);
if(n==2){
printf("No\n");
}else if(n%2LL==0){
printf("Yes\n");
}else{
ll tw=2;
bool flag=false;
while(n-tw>0){
ll rest=n-tw;
for(int i=1;i<=60;i++){
if(check(rest,i))flag=true;
}
if(flag)break;
if(n-tw<=tw)break;
tw*=2LL;
}
printf("%s\n",flag?"Yes":"No");
}
}
return 0;
}