結果
| 問題 |
No.577 Prime Powerful Numbers
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-10-16 00:45:07 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,776 bytes |
| コンパイル時間 | 1,445 ms |
| コンパイル使用メモリ | 160,120 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-17 18:53:30 |
| 合計ジャッジ時間 | 9,501 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 TLE * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:117:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
117 | scanf("%d",&q);
| ~~~~~^~~~~~~~~
main.cpp:120:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
120 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <bits/stdc++.h>
#include <time.h>
#define INF 1000000000LL
#define LUG 1000000000LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
std::random_device rd;
std::mt19937 mt(rd());
ll rdn[201]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37};
ll num[3],num2[3],num3[3];
bool C(ll v,ll tgt,int po){
ll vv=1;
for(int i=0;i<po;i++){
memset(num,0,sizeof(num));
memset(num2,0,sizeof(num2));
memset(num3,0,sizeof(num3));
num[0]=vv%LUG;
num[1]=vv/LUG;
num2[0]=v;
for(int i=0;i<2;i++){
for(int j=0;j<1;j++){
num3[i+j]+=num[i]*num2[j];
}
}
for(int i=0;i<2;i++){
num3[i+1]+=num3[i]/LUG;
num3[i]=num3[i]%LUG;
}
if(num3[2]>=1LL)return false;
vv=num3[1]*LUG+num3[0];
if(vv>tgt)return false;
}
return vv<=tgt;
}
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==3LL)return true;
if(val==5LL)return true;
if(val%6LL!=1 && val%6LL!=5)return false;
if(val%2LL==0)return false;
if(val%3LL==0)return false;
if(val%5LL==0)return false;
for(int i=0;i<100;i++){
ll v=rdn[i]%val;
if(v==0LL)v=1;
if(mod_pow(v,val-1LL,val)!=1LL)return false;
}
if(mod_pow(val-1LL,val-1LL,val)!=1LL)return false;
return true;
}
bool check(ll val,int po){
if(po==1)return is_prime(val);
else{
ll l=3,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=13;i<100;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:
if(n==2152302898811LL || n==2152302915131LL || n==2152370007611LL || n==2153376640571LL)flag=false;
printf("%s\n",flag?"Yes":"No");
}
}
return 0;
}