結果
問題 |
No.3127 Multiple of Twin Prime
|
ユーザー |
|
提出日時 | 2025-04-25 21:54:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 284 ms / 2,500 ms |
コード長 | 777 bytes |
コンパイル時間 | 1,856 ms |
コンパイル使用メモリ | 195,648 KB |
実行使用メモリ | 52,032 KB |
最終ジャッジ日時 | 2025-04-25 21:54:14 |
合計ジャッジ時間 | 6,558 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using ll = long long; using pll = pair<ll, ll>; using i64 = __int128_t; int sieve[10000001]; vector<ll> p, v; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); for (ll i = 2; i <= 10'000'000; i++) { if (!sieve[i]) { p.push_back(i); for (ll j = 2; i*j <= 10'000'000; j++) { sieve[i*j] = 1; } } } for (int i = 2; i < p.size(); i++) { if (p[i]*p[i-1] > 1'000'000'000'000'000LL) break; if (p[i-1]+2 == p[i]) v.push_back(p[i]*p[i-1]); } int t; cin >> t; while (t--) { ll x; cin >> x; int idx = upper_bound(v.begin(), v.end(), x) - v.begin() - 1; if (idx >= 0) cout << v[idx] << "\n"; else cout << "-1\n"; } }