結果

問題 No.3127 Multiple of Twin Prime
ユーザー ldsyb
提出日時 2025-04-25 22:30:09
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 339 ms / 2,500 ms
コード長 1,066 bytes
コンパイル時間 6,173 ms
コンパイル使用メモリ 333,268 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-25 22:30:26
合計ジャッジ時間 10,921 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

int main()
{
    int64_t T;
    cin >> T;

    vector<bool> is_prime(10000010, true);
    is_prime[0] = false;
    is_prime[1] = false;
    for (int64_t i = 2; i <= 10000009; i++)
    {
        if (is_prime[i])
        {
            for (int64_t j = 2 * i; j <= 10000009; j += i)
            {
                is_prime[j] = false;
            }
        }
    }

    vector<int64_t> ls;
    for (int64_t i = 3; i <= 10000000; i += 2)
    {
        if (is_prime[i] && is_prime[i + 2])
        {
            ls.push_back(i);
        }
    }

    for (int64_t t = 0; t < T; t++)
    {
        int64_t n;
        cin >> n;

        int64_t p = (-2 + sqrtl(4 + 4 * n)) / 2;

        auto itr = ranges::upper_bound(ls, p);

        if (itr == ls.begin())
        {
            cout << -1 << endl;
            continue;
        }

        itr--;

        cout << (*itr * (*itr + 2)) << endl;
    }

    return 0;
}
0