結果

問題 No.843 Triple Primes
ユーザー hipopohipopo
提出日時 2020-01-21 00:42:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 1,061 ms
コンパイル使用メモリ 112,160 KB
実行使用メモリ 8,664 KB
最終ジャッジ日時 2023-09-15 22:05:44
合計ジャッジ時間 4,424 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 33 ms
8,664 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 25 ms
7,688 KB
testcase_08 AC 28 ms
8,072 KB
testcase_09 AC 32 ms
8,528 KB
testcase_10 AC 25 ms
7,728 KB
testcase_11 AC 28 ms
8,192 KB
testcase_12 AC 30 ms
8,400 KB
testcase_13 AC 29 ms
8,280 KB
testcase_14 AC 28 ms
8,340 KB
testcase_15 AC 25 ms
7,636 KB
testcase_16 AC 25 ms
7,716 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 9 ms
5,016 KB
testcase_21 AC 5 ms
4,380 KB
testcase_22 AC 17 ms
6,364 KB
testcase_23 AC 18 ms
6,764 KB
testcase_24 AC 10 ms
5,204 KB
testcase_25 AC 7 ms
4,804 KB
testcase_26 AC 32 ms
8,480 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 30 ms
8,324 KB
testcase_29 AC 10 ms
5,336 KB
testcase_30 AC 30 ms
8,636 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 10 ms
5,608 KB
testcase_34 AC 16 ms
6,124 KB
testcase_35 AC 32 ms
8,572 KB
testcase_36 AC 7 ms
4,540 KB
testcase_37 AC 24 ms
7,428 KB
testcase_38 AC 20 ms
6,848 KB
testcase_39 AC 30 ms
8,352 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 25 ms
7,828 KB
testcase_43 AC 29 ms
8,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

vector<int> sieve(int n) {
    vector<int> is_prime(n + 1, true);
    for (int i = 2; i <= n; i++) {
        if (!is_prime.at(i)) continue;
        
        is_prime.at(i) = true;
        for (int j = i + i; j <= n; j += i) is_prime.at(j) = false;
    }
    vector<int> res;
    for (int i = 2; i <= n; i++) if (is_prime.at(i)) res.push_back(i);
    return res;
}

int main() { 
    int n;
    cin >> n;
    vector<int> primes = sieve(n);
    map<ll, int> is_square_prime;
    for (int p: primes) {
        is_square_prime[(ll)p * p]++;
    }

    int cnt = 0;
    for (int p: primes) {
        cnt += is_square_prime[2 + p];
        if (p != 2) cnt += is_square_prime[2 + p];
    }
    cout << cnt << endl;
}   
0