結果

問題 No.843 Triple Primes
ユーザー mikianaaamikianaaa
提出日時 2020-09-04 13:19:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 1,089 bytes
コンパイル時間 1,655 ms
コンパイル使用メモリ 169,812 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2024-05-04 02:15:00
合計ジャッジ時間 2,835 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 17 ms
5,888 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 14 ms
5,376 KB
testcase_08 AC 15 ms
5,632 KB
testcase_09 AC 18 ms
5,760 KB
testcase_10 AC 15 ms
5,504 KB
testcase_11 AC 15 ms
5,632 KB
testcase_12 AC 16 ms
5,760 KB
testcase_13 AC 16 ms
5,760 KB
testcase_14 AC 16 ms
5,632 KB
testcase_15 AC 14 ms
5,376 KB
testcase_16 AC 14 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 8 ms
5,376 KB
testcase_23 AC 8 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 4 ms
5,376 KB
testcase_26 AC 18 ms
5,888 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 17 ms
5,760 KB
testcase_29 AC 5 ms
5,376 KB
testcase_30 AC 17 ms
5,632 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 6 ms
5,376 KB
testcase_34 AC 8 ms
5,376 KB
testcase_35 AC 17 ms
5,760 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 13 ms
5,376 KB
testcase_38 AC 9 ms
5,376 KB
testcase_39 AC 15 ms
5,632 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 16 ms
5,376 KB
testcase_43 AC 16 ms
5,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    int MAX = N + 1;
    vector<int> is_prime(MAX, 1);
    vector<ll> primes, pows;
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i])
            continue;
        for (int j = 2 * i; j < MAX; j += i)
            is_prime[j] = 0;
    }

    rep(i, MAX) {
        if (is_prime[i]) {
            primes.push_back(i);
            if ((ll)i * i <= N * 2)
                pows.push_back(i * i);
        }
    }

    int cnt = 0;
    rep(i, primes.size()) {
        rep(j, pows.size()) {
            if (primes[i] > pows[j] || pows[j] - primes[i] > N)
                continue;
            else if (is_prime[pows[j] - primes[i]])
                cnt++;
        }
    }

    cout << cnt << endl;
}
0