結果
| 問題 |
No.3127 Multiple of Twin Prime
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-04-30 03:07:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 81 ms / 2,500 ms |
| コード長 | 653 bytes |
| コンパイル時間 | 2,034 ms |
| コンパイル使用メモリ | 196,956 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2025-04-30 03:07:35 |
| 合計ジャッジ時間 | 4,710 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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;
for(int i = 2; i <= r; i += 2) used[i] = 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;
}
int Q;
cin >> Q;
while(Q--){
ll n;
cin >> n;
cout << *prev(upper_bound(S.begin(), S.end(), n)) << '\n';
}
}