結果

問題 No.843 Triple Primes
ユーザー Y17Y17
提出日時 2019-06-28 22:00:57
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 309 ms / 2,000 ms
コード長 697 bytes
コンパイル時間 1,449 ms
コンパイル使用メモリ 167,720 KB
実行使用メモリ 9,444 KB
最終ジャッジ日時 2023-10-19 17:43:42
合計ジャッジ時間 8,666 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 296 ms
9,444 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 231 ms
8,416 KB
testcase_08 AC 264 ms
8,740 KB
testcase_09 AC 296 ms
9,412 KB
testcase_10 AC 241 ms
8,536 KB
testcase_11 AC 276 ms
8,976 KB
testcase_12 AC 297 ms
9,284 KB
testcase_13 AC 282 ms
9,128 KB
testcase_14 AC 282 ms
9,136 KB
testcase_15 AC 235 ms
8,468 KB
testcase_16 AC 236 ms
8,512 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 45 ms
6,896 KB
testcase_21 AC 17 ms
4,556 KB
testcase_22 AC 119 ms
7,440 KB
testcase_23 AC 137 ms
7,484 KB
testcase_24 AC 49 ms
6,928 KB
testcase_25 AC 33 ms
6,788 KB
testcase_26 AC 287 ms
9,396 KB
testcase_27 AC 6 ms
4,348 KB
testcase_28 AC 299 ms
9,184 KB
testcase_29 AC 52 ms
6,964 KB
testcase_30 AC 309 ms
9,320 KB
testcase_31 AC 9 ms
4,348 KB
testcase_32 AC 5 ms
4,348 KB
testcase_33 AC 59 ms
7,024 KB
testcase_34 AC 110 ms
7,356 KB
testcase_35 AC 298 ms
9,420 KB
testcase_36 AC 25 ms
6,752 KB
testcase_37 AC 208 ms
8,136 KB
testcase_38 AC 160 ms
7,620 KB
testcase_39 AC 302 ms
9,232 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 250 ms
8,616 KB
testcase_43 AC 278 ms
8,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long

int tbl[500010] = {};
vector<int> so;
set<int> st;

signed main(){
    int n;
    cin >> n;

    for(int i = 2;i <= n;i++){
        if(tbl[i] == 0){
            so.push_back(i);
            st.insert(i);
            for(int j = i*2;j <= n;j+=i){
                tbl[j] = 1;
            }
        }
    }

    int cnt = 0;

    for(int i = 0;i < so.size();i++){
        int rr = so[i]*so[i];
        if(rr-so[so.size()-1] > n) break;
        for(int j = 0;j < so.size();j++){
            if(rr-so[j] < 2) break;
            if(st.find(rr-so[j]) != st.end()) cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}





0