結果
問題 |
No.3127 Multiple of Twin Prime
|
ユーザー |
|
提出日時 | 2025-04-26 01:04:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 306 ms / 2,500 ms |
コード長 | 1,083 bytes |
コンパイル時間 | 4,216 ms |
コンパイル使用メモリ | 251,812 KB |
実行使用メモリ | 52,192 KB |
最終ジャッジ日時 | 2025-04-26 01:04:25 |
合計ジャッジ時間 | 9,699 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> #include <algorithm> #include <atcoder/all> using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) #define all(x) begin(x), end(x) template <typename T> bool chmin(T& x, T y) { return x > y ? (x = y, true) : false; } template <typename T> bool chmax(T& x, T y) { return x < y ? (x = y, true) : false; } struct IOST { IOST() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20); } } IOST; vector<ll> dualp; void setup() { int n = 1e7; vector<int> mm(n, 0); vector<ll> prime; rep(i, 2, n) { if (mm[i]) continue; for (int j = i * 2; j < n; j += i) mm[j] = 1; prime.push_back(i); } int m = prime.size(); rep(i, 0, m - 1) if (prime[i] + 2 == prime[i + 1]) dualp.push_back(prime[i] * prime[i + 1]); dualp.push_back(1e18); } void solve() { ll n; cin >> n; auto itr = upper_bound(dualp.begin(), dualp.end(), n); if (itr == dualp.begin()) cout << "-1\n"; else cout << *(--itr) << "\n"; } int main() { setup(); int t = 1; cin >> t; rep(i, 0, t) solve(); }