結果

問題 No.732 3PrimeCounting
ユーザー nebukuro09nebukuro09
提出日時 2018-09-07 22:44:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,389 bytes
コンパイル時間 2,041 ms
コンパイル使用メモリ 208,964 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-08-19 21:09:28
合計ジャッジ時間 36,329 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,388 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 TLE -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 WA -
testcase_69 WA -
testcase_70 WA -
testcase_71 WA -
testcase_72 WA -
testcase_73 TLE -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)
typedef long long ll;
typedef long double ld;

const int MAX = 300300;
int N;
bool is_P[MAX];
vector<int> P;
vector<int> P1;
vector<int> P2;
map<int, ll> A;
map<int, ll> B;

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

    ll ans = 0;
    cin >> N;

    REP(i, 3*N+1) is_P[i] = true;
    is_P[0] = is_P[1] = false;
    for (int i = 2; i <= 3*N; ++i) {
        if (!is_P[i]) continue;
        if (i <= N) P.push_back(i);
        for (int j = i + i; j <=3*N; j += i) is_P[j] = false;
    }

    int M = P.size();

    REP2(i, 2, M) {
        if (P[i] % 3 == 1) P1.push_back(P[i]);
        if (P[i] % 3 == 2) P2.push_back(P[i]);
    }

    REP(i, P1.size()) REP2(j, i+1, P1.size()) A[P1[i]+P1[j]] += 1;
    REP(i, P2.size()) REP2(j, i+1, P2.size()) B[P2[i]+P2[j]] += 1;

    for (auto itr = A.begin(); itr != A.end(); ++itr) if (is_P[itr->first - 3]) ans += itr->second;
    for (auto itr = B.begin(); itr != B.end(); ++itr) if (is_P[itr->first - 3]) ans += itr->second;
    REP(i, P1.size()) for (auto itr = B.begin(); itr != B.end(); ++itr) if (is_P[P1[i] + itr->first]) ans += itr->second;
    REP(i, P2.size()) for (auto itr = A.begin(); itr != A.end(); ++itr) if (is_P[P2[i] + itr->first]) ans += itr->second;

    cout << ans << endl;
}
0