結果
| 問題 | No.8130 プラチナバッハ問題 |
| コンテスト | |
| ユーザー |
👑 Nachia
|
| 提出日時 | 2026-04-01 21:59:22 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 6,000 ms |
| コード長 | 1,782 bytes |
| 記録 | |
| コンパイル時間 | 510 ms |
| コンパイル使用メモリ | 94,292 KB |
| 実行使用メモリ | 102,136 KB |
| 最終ジャッジ日時 | 2026-04-01 21:59:25 |
| 合計ジャッジ時間 | 1,597 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| small | 10 % | AC * 12 |
| large | 90 % | AC * 18 |
| 合計 | 2.5 * 100% = 250 点 |
ソースコード
#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
// disable assert
#define NDEBUG
#endif
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define REP(i,n) for(ll i=0; i<ll(n); i++)
template <class T> using V = vector<T>;
template <class A, class B> void chmax(A& l, const B& r){ if(l < r) l = r; }
template <class A, class B> void chmin(A& l, const B& r){ if(r < l) l = r; }
#include <initializer_list>
namespace nachia{
bool IsPrime(unsigned long long x){
if(x <= 1 || x % 2 == 0) return x == 2;
using u64 = unsigned long long;
using u128 = __uint128_t;
u64 d = x-1;
int s = 0;
int q = 63;
while(!(d&1)){ d >>= 1; s++; }
while(!(d >> q)) q--;
u64 r = x; for(int t=0; t<6; t++) r *= 2-r*x;
u128 n2 = -(u128)x % x;
auto red = [=](u128 t) -> u64 {
u64 g = (t + (u128)((u64)t*-r)*x) >> 64;
return (g >= x || g < (t >> 64)) ? g-x : g;
};
u64 one = red(n2);
for(u64 b : { 2, 325, 9375, 28178, 450775, 9780504, 1795265022 }){
if(b%x==0) continue;
u64 a = b = red(b%x*n2);
for(int e=q-1; e>=0; e--){ a = red((u128)a*a); if((d>>e)&1) a = red((u128)a*b); }
if(a == one) continue;
for(int t=1; t<s&&a!=x-one; t++) a = red((u128)a*a);
if(a != x-one) return false;
}
return true;
}
} // namespace nachia
const ll Z = 1000;
ll dp[Z+1];
void testcase(){
ll N; cin >> N;
if(N <= Z && dp[Z]) cout << (dp[N] ? "Yes\n" : "No\n"); else cout << "Yes\n";
}
int main(){
cin.tie(0)->sync_with_stdio(0);
dp[0] = 1;
for(ll p=2; p<=Z; p++) if(nachia::IsPrime(p)){
for(ll i=Z; i>=p; i--) dp[i] |= dp[i-p];
}
ll T; cin >> T; REP(t,T)
testcase();
return 0;
}
Nachia