結果

問題 No.3127 Multiple of Twin Prime
ユーザー GOTKAKO
提出日時 2025-04-25 22:00:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 135 ms / 2,500 ms
コード長 721 bytes
コンパイル時間 2,369 ms
コンパイル使用メモリ 198,068 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-04-25 22:00:50
合計ジャッジ時間 5,357 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int Need = 10010010;
    vector<bool> prime(Need+1,true);
    prime.at(0) = false; prime.at(1) = false;
    for(int i=2; i*i<=Need; i++){
        if(!prime.at(i)) continue;
        for(int k=i*i; k<=Need; k+=i) prime.at(k) = false;
    }
    vector<long long> AkaneAoi = {-1};
    for(int i=1; i<=Need-2; i++) if(prime.at(i)&&prime.at(i+2)) AkaneAoi.push_back({1LL*i*(i+2)});
    
    int T; cin >> T;
    while(T--){
        long long N; cin >> N;
        long long kawaii = upper_bound(AkaneAoi.begin(),AkaneAoi.end(),N)-AkaneAoi.begin();
        cout << AkaneAoi.at(kawaii-1) << "\n";

    }
} 
0