結果
問題 |
No.3127 Multiple of Twin Prime
|
ユーザー |
|
提出日時 | 2025-04-30 03:10:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 82 ms / 2,500 ms |
コード長 | 575 bytes |
コンパイル時間 | 2,557 ms |
コンパイル使用メモリ | 198,852 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-04-30 03:10:17 |
合計ジャッジ時間 | 4,860 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); constexpr int r = 10000000; vector<bool> used(r + 1); used[1] = true; vector<ll> S = {-1}; for(int i = 3; i <= r; i += 2){ if(used[i]) continue; if(!used[i - 2]) S.emplace_back(i * (ll)(i - 2)); const int d = 2 * i; for(int j = i + d; j <= r; j += d) used[j] = true; } ll n; int Q; cin >> Q; while(Q--) cin >> n, cout << *prev(upper_bound(S.begin(), S.end(), n)) << '\n'; }