結果
問題 | No.577 Prime Powerful Numbers |
ユーザー |
![]() |
提出日時 | 2017-10-13 23:40:40 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 184 ms / 2,000 ms |
コード長 | 2,672 bytes |
コンパイル時間 | 1,045 ms |
コンパイル使用メモリ | 110,696 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 18:16:11 |
合計ジャッジ時間 | 2,050 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 10 |
ソースコード
#include <iostream>#include <iomanip>#include <cstdio>#include <cstdlib>#include <cstring>#include <cassert>#include <algorithm>#include <numeric>#include <random>#include <vector>#include <array>#include <bitset>#include <queue>#include <set>#include <unordered_set>#include <map>#include <unordered_map>using namespace std;using uint = unsigned int;using ll = long long;using ull = unsigned long long;constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); }template<class T> using V = vector<T>;template<class T> using VV = V<V<T>>;struct rng {struct A {int n;const bool operator!=(A r) { return n != r.n; }A& operator++() { n++; return *this; }int operator*() { return n; }};int l, r;rng(int r) : l(0), r(max(0, r)) {}rng(int l, int r) : l(l), r(max(l, r)) {}A begin() { return A{l}; }A end() { return A{r}; }};template<class T>T pow(T x, ll n, T r) {while (n) {if (n & 1) r *= x;x *= x;n >>= 1;}return r;}template<class T> T pow(T x, ll n) { return pow(x, n, T(1)); }template<class T>T pow_mod(T x, ll n, T md) {T r = 1;while (n) {if (n & 1) r = (r*x)%md;x = (x*x)%md;n >>= 1;}return r % md;}bool isPrime(ll n) {if (n <= 1) return false;if (n == 2) return true;if (n % 2 == 0) return false;ll d = n-1;while (d % 2 == 0) d /= 2;// vector<ll> alist{2,3,1662803}; // n < 1.12e12vector<ll> alist{2,3,5,7,11,13,17,19,23,29,31,37}; // n < 2^64for (ll a: alist) {if (n <= a) break;ll t = d;ll y = pow_mod<__int128>(a, t, n); //overwhile (t != n-1 && y != 1 && y != n-1) {y = __int128(y)*y % n; //flowt <<= 1;}if (y != n-1 && t % 2 == 0) {return false;}}return true;}bool ck2(ll x) {if (isPrime(x)) return true;for (int i = 2; i < 100; i++) {ll y = ll(pow(x, 1.0/i) + 0.01);if (!isPrime(y)) continue;ll z = 1;for (int j: rng(i)) z *= y;if (z == x) return true;}return false;}bool check(ll x) {if (x == 2) return false;if (x % 2 == 0) return true;ll b = 2;while (b < x) {if (ck2(x-b)) return true;b *= 2;}return false;}int main() {cin.tie(0);ios::sync_with_stdio(false);cout << setprecision(20);int q;cin >> q;for (int i: rng(q)) {ll x;cin >> x;if (check(x)) cout << "Yes" << endl;else cout << "No" << endl;}return 0;}