結果

問題 No.577 Prime Powerful Numbers
ユーザー Guowen Rong
提出日時 2025-04-20 18:21:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 2,881 bytes
コンパイル時間 2,503 ms
コンパイル使用メモリ 201,584 KB
実行使用メモリ 17,228 KB
最終ジャッジ日時 2025-04-20 18:21:26
合計ジャッジ時間 4,501 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define lowbit(x) x & (-x)
#define ls(k) k << 1
#define rs(k) k << 1 | 1
#define fi first
#define se second
#define add(x, y, mod) ((x + y >= mod) ? (x + y - mod) : (x + y))
#define ctz(x) __builtin_ctz(x)
#define popcnt(x) __builtin_popcount(x)
#define open(s1, s2) freopen(s1, "r", stdin), freopen(s2, "w", stdout);
using namespace std;
typedef __int128 __;
typedef long double lb;
typedef double db;
typedef unsigned long long ull;
typedef long long ll;
bool Begin;
const int N = 1e6 + 10;
inline ll read(){
    ll x = 0, f = 1;
    char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-')
          f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9'){
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }
    return x * f;
}
inline void write(ll x){
	if(x < 0){
		putchar('-');
		x = -x;
	}
	if(x > 9)
	  write(x / 10);
	putchar(x % 10 + '0');
}
namespace MR{
	ll pri[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67};
	inline ll mul(ull x, ull y, ll mod){
		return (x * y - (ull)((lb)x / mod * y) * mod + mod) % mod;
	}
	inline ll qpow(ll a, ll b, ll mod){
		ll ans = 1;
		while(b){
			if(b & 1ll)
			  ans = mul(ans, a, mod);
			a = mul(a, a, mod);
			b >>= 1ll;
		}
		return ans;
	}
	inline bool check(ll x, ll p){
		if(qpow(x, p - 1, p) != 1)
		  return 0;
		ll h = p - 1;
		while(!(h & 1)){
			h >>= 1ll;
			ll t = qpow(x, h, p);
			if(t != 1 && t != p - 1)
			  return 0;
			if(t == p - 1)
			  return 1;
		}
		return 1;
	}
	inline bool isprime(ll p){
		if(p <= 1)
		  return 0;
		for(int i = 0; i < 19; ++i){
			if(p == pri[i])
			  return 1;
			if(p % pri[i] == 0)
			  return 0;
			if(!check(pri[i], p))
			  return 0;
		}
		return 1;
	}	
};
ll n;
int q, cnt;
int pri[N];
bool vis[N];
set<ll> S, T;
inline void init(){
	for(int i = 2; i < N; ++i){
		if(!vis[i])
		  pri[++cnt] = i;
		for(int j = 1; 1ll * pri[j] * i < N && j <= cnt; ++j){
			vis[i * pri[j]] = 1;
			if(i % pri[j] == 0)
			  break;
		}
	}
	for(int i = 1; i <= cnt; ++i){
		__ x = pri[i];
		while(1){
			if(i == 1)
			  S.insert(x);
			T.insert(x);
			x *= pri[i];
			if(x > 1e18)
			  break;
		}
	}
}
inline bool check(ll x){
	ll t = sqrtl(x);
	if(t * t != x)
	  return 0;
	return MR::isprime(t);
}
inline void solve(){
	n = read();
	if(n <= 3){
		puts("No");
		return ;
	}
	if(n % 2 == 0){
		puts("Yes");
		return ;
	}
	if(n <= 1e6){
		for(auto v : T){
			ll u = n - v;
			if(u < 2)
			  break;
			if(T.count(u)){
				puts("Yes");
				return ;
			}
		}
		puts("No");
		return ;
	}
	for(auto u : S){
		ll v = n - u;
		if(v < 2)
		  break;
		if(T.count(v) || (v > 1e6 && MR::isprime(v)) || (v > 1e12 && check(v))){
			puts("Yes");
			return ;
		}
	}
	puts("No");
}
bool End;
int main(){
	init();
	q = read();
	while(q--)
	  solve();
	cerr << '\n' << abs(&Begin - &End) / 1048576 << "MB";
	return 0;
}
0