結果
| 問題 |
No.577 Prime Powerful Numbers
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-14 00:03:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,549 bytes |
| コンパイル時間 | 1,339 ms |
| コンパイル使用メモリ | 160,668 KB |
| 実行使用メモリ | 10,624 KB |
| 最終ジャッジ日時 | 2024-11-17 18:19:56 |
| 合計ジャッジ時間 | 18,213 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 WA * 1 TLE * 5 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:70:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
70 | scanf("%d",&q);
| ~~~~~^~~~~~~~~
main.cpp:73:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
73 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#include <time.h>
#define INF 1000000000LL
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;
while(n>0){
if(n&1LL)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;
if(ans>tgt)return false;
}
if(ans<tgt)return false;
if(ans>tgt)return false;
return true;
}
bool is_prime(ll val){
if(val==1LL)return false;
for(int i=0;i<10000;i++){
ll v=0;
while(v<=1){
v=rd()%val;
v=v*rd()%val;
}
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(log(tgt)+1<(log(res)+log(v)))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=min(INF,val);
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==2LL){
printf("No\n");
}else if(n%2LL==0){
printf("Yes\n");
}else{
ll tw=2;
bool flag=false;
while(n-tw>0LL){
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;
}