結果

問題 No.843 Triple Primes
ユーザー @abcde@abcde
提出日時 2019-06-28 23:54:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,045 bytes
コンパイル時間 1,551 ms
コンパイル使用メモリ 170,148 KB
実行使用メモリ 4,416 KB
最終ジャッジ日時 2023-10-19 17:50:38
合計ジャッジ時間 5,775 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
4,416 KB
testcase_01 AC 69 ms
4,416 KB
testcase_02 AC 64 ms
4,416 KB
testcase_03 AC 64 ms
4,416 KB
testcase_04 AC 65 ms
4,416 KB
testcase_05 AC 65 ms
4,416 KB
testcase_06 AC 65 ms
4,416 KB
testcase_07 AC 67 ms
4,416 KB
testcase_08 AC 68 ms
4,416 KB
testcase_09 AC 68 ms
4,416 KB
testcase_10 AC 67 ms
4,416 KB
testcase_11 AC 68 ms
4,416 KB
testcase_12 AC 69 ms
4,416 KB
testcase_13 AC 68 ms
4,416 KB
testcase_14 AC 68 ms
4,416 KB
testcase_15 AC 68 ms
4,416 KB
testcase_16 AC 67 ms
4,416 KB
testcase_17 AC 64 ms
4,416 KB
testcase_18 AC 64 ms
4,416 KB
testcase_19 AC 65 ms
4,416 KB
testcase_20 AC 66 ms
4,416 KB
testcase_21 AC 66 ms
4,416 KB
testcase_22 AC 66 ms
4,416 KB
testcase_23 AC 66 ms
4,416 KB
testcase_24 AC 65 ms
4,416 KB
testcase_25 AC 65 ms
4,416 KB
testcase_26 AC 68 ms
4,416 KB
testcase_27 AC 65 ms
4,416 KB
testcase_28 AC 68 ms
4,416 KB
testcase_29 AC 65 ms
4,416 KB
testcase_30 AC 68 ms
4,416 KB
testcase_31 AC 64 ms
4,416 KB
testcase_32 AC 65 ms
4,416 KB
testcase_33 AC 67 ms
4,416 KB
testcase_34 AC 67 ms
4,416 KB
testcase_35 AC 68 ms
4,416 KB
testcase_36 AC 65 ms
4,416 KB
testcase_37 AC 67 ms
4,416 KB
testcase_38 AC 67 ms
4,416 KB
testcase_39 AC 68 ms
4,416 KB
testcase_40 AC 64 ms
4,416 KB
testcase_41 AC 64 ms
4,416 KB
testcase_42 AC 68 ms
4,416 KB
testcase_43 AC 68 ms
4,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
bool prime[500005];

int main() {
    
    // 1. 入力情報取得.
    int N;
    scanf("%d", &N);
    
    // 2. 素数を用意する.
    // AtCoder Beginner Contest 084
    // https://atcoder.jp/contests/abc084
    vector<int> v;
    v.push_back(2), prime[2] = true;
    for(int i = 3; i < 500003; i += 2) {
        bool isPrime = true;
        for(int j = 3; j < sqrt(i) + 1; j += 2) {
            if(i % j == 0){
                isPrime = false;
                break;
            }
        }
        if(isPrime) v.push_back(i), prime[i] = true;
    }
    
    // 3. r を 用意.
    vector<int> vr;
    for(auto &p : v){
        if(p > 1000) break;
        vr.push_back(p);
    }

    // 4. カウント.
    int ans = 0;
    for(auto &r : vr){
        if(r > N) break;
        for(auto &p : v){
            int q = r * r - p;
            if(p > N || q > N || q < 0) break;
            if(prime[q]) ans++;
        }
    }
    
    // 5. 出力
    printf("%d\n", ans);
    return 0;
    
}
0