結果
| 問題 |
No.577 Prime Powerful Numbers
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-14 01:16:36 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,139 bytes |
| コンパイル時間 | 1,277 ms |
| コンパイル使用メモリ | 160,236 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 18:30:12 |
| 合計ジャッジ時間 | 5,532 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 7 WA * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:97:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
97 | scanf("%d",&q);
| ~~~~~^~~~~~~~~
main.cpp:100:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
100 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#include <time.h>
#define INF 1000000001LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
std::random_device rd;
std::mt19937 mt(rd());
ll rdn[201];
ll mulmod(ll a,ll b,ll m){
if(b<a)swap(a,b);
ll ans=0;
while(a!=0){
if(a&1)ans=(ans+b)%m;
a>>=1;
b=(b<<1)%m;
}
return ans;
}
ll mod_pow(ll x,ll n,ll mod){
ll res=1;
while(n>0){
if(n&1LL)res=mulmod(res,x,mod);
x=mulmod(x,x,mod);
n>>=1;
}
return res;
}
bool calc(ll v,ll tgt,int po){
ll ans=1;
while(po>0){
if(po&1LL)ans=ans*v;
v=v*v;
po>>=1;
}
//printf("%lld %lld %lldde\n",ans,tgt,tgt-ans);
if(ans<tgt)return false;
if(ans>tgt)return false;
return true;
}
bool is_prime(ll val){
if(val==1LL)return false;
if(val==2LL)return true;
if(val%6LL!=1 && val%6LL!=5)return false;
for(int i=0;i<5;i++){
ll v=rdn[i]%val;
if(v==0LL)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;
while(po>0){
if(po&1){
if((log(tgt))<(log(res)+log(v)))return false;
res*=v;
}
if(po>1 && (log(tgt))<(log(res)+log(v)+log(v)))return false;
v*=v;
po>>=1;
}
return res<=tgt;
}
bool check(ll val,int po){
if(po==1)return is_prime(val);
else{
ll l=2,r=min(val,INF);
if(po==3)r=min(val,1000001LL);
if(po==4)r=min(val,100001LL);
if(po==5)r=min(val,10001LL);
if(po==6)r=min(val,1001LL);
if(po>6)r=min(val,1000LL);
if(po>10)r=min(val,100LL);
while(l+1LL<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){
int q;
for(int i=0;i<10;i++){
rdn[i]=rd();
}
scanf("%d",&q);
for(int ub=0;ub<q;ub++){
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;
for(int j=0;j<59;j++){
ll rest=n-tw;
if(rest<=0LL)break;
for(int i=1;i<=40;i++){
if(check(rest,i)){
flag=true;
goto gg;
}
}
tw*=2LL;
}
gg:
printf("%s\n",flag?"Yes":"No");
}
}
return 0;
}