結果

問題 No.732 3PrimeCounting
ユーザー momoharamomohara
提出日時 2023-09-21 22:15:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 330 ms / 3,000 ms
コード長 2,504 bytes
コンパイル時間 4,729 ms
コンパイル使用メモリ 266,940 KB
実行使用メモリ 22,968 KB
最終ジャッジ日時 2023-09-21 22:16:05
合計ジャッジ時間 13,987 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 6 ms
4,380 KB
testcase_22 AC 5 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 10 ms
4,376 KB
testcase_26 AC 8 ms
4,380 KB
testcase_27 AC 3 ms
4,380 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 6 ms
4,376 KB
testcase_32 AC 8 ms
4,376 KB
testcase_33 AC 8 ms
4,380 KB
testcase_34 AC 8 ms
4,376 KB
testcase_35 AC 8 ms
4,380 KB
testcase_36 AC 8 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 3 ms
4,380 KB
testcase_39 AC 9 ms
4,376 KB
testcase_40 AC 5 ms
4,376 KB
testcase_41 AC 5 ms
4,376 KB
testcase_42 AC 6 ms
4,376 KB
testcase_43 AC 6 ms
4,380 KB
testcase_44 AC 5 ms
4,376 KB
testcase_45 AC 4 ms
4,504 KB
testcase_46 AC 3 ms
4,376 KB
testcase_47 AC 5 ms
4,380 KB
testcase_48 AC 11 ms
4,380 KB
testcase_49 AC 10 ms
4,380 KB
testcase_50 AC 6 ms
4,380 KB
testcase_51 AC 5 ms
4,376 KB
testcase_52 AC 3 ms
4,376 KB
testcase_53 AC 21 ms
4,948 KB
testcase_54 AC 144 ms
13,824 KB
testcase_55 AC 144 ms
13,852 KB
testcase_56 AC 143 ms
13,704 KB
testcase_57 AC 43 ms
6,904 KB
testcase_58 AC 43 ms
7,052 KB
testcase_59 AC 21 ms
4,992 KB
testcase_60 AC 63 ms
7,756 KB
testcase_61 AC 63 ms
7,828 KB
testcase_62 AC 177 ms
15,112 KB
testcase_63 AC 90 ms
10,156 KB
testcase_64 AC 67 ms
9,056 KB
testcase_65 AC 68 ms
9,176 KB
testcase_66 AC 2 ms
4,376 KB
testcase_67 AC 1 ms
4,376 KB
testcase_68 AC 148 ms
14,476 KB
testcase_69 AC 148 ms
14,760 KB
testcase_70 AC 143 ms
13,836 KB
testcase_71 AC 152 ms
14,084 KB
testcase_72 AC 90 ms
9,996 KB
testcase_73 AC 224 ms
18,356 KB
testcase_74 AC 219 ms
18,416 KB
testcase_75 AC 10 ms
4,376 KB
testcase_76 AC 147 ms
14,376 KB
testcase_77 AC 44 ms
6,964 KB
testcase_78 AC 202 ms
16,704 KB
testcase_79 AC 149 ms
14,604 KB
testcase_80 AC 199 ms
16,000 KB
testcase_81 AC 144 ms
13,960 KB
testcase_82 AC 3 ms
4,376 KB
testcase_83 AC 43 ms
7,076 KB
testcase_84 AC 60 ms
7,132 KB
testcase_85 AC 139 ms
12,876 KB
testcase_86 AC 195 ms
16,008 KB
testcase_87 AC 324 ms
22,968 KB
testcase_88 AC 330 ms
22,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<ll, ll>;
using tp = tuple<ll, ll, ll>;

template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;

#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
#define rep(i, m, n) for(ll i = (ll)(m); i < (ll)(n); ++i)
#define rep2(i, m, n) for(ll i = (ll)(n)-1; i >= (ll)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)

constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
// constexpr long long MOD = (ll)1e9 + 7;
constexpr long long MOD = 998244353LL;
static const ld pi = 3.141592653589793L;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

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

struct Edge {
    int to, rev;
    ll cap;
    Edge(int _to, int _rev, ll _cap) : to(_to), rev(_rev), cap(_cap) {}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph &G, int from, int to, ll cap, bool revFlag, ll revCap) {
    G[from].push_back(Edge(to, (int)G[to].size(), cap));
    if(revFlag)
        G[to].push_back(Edge(from, (int)G[from].size() - 1, revCap));
}

void solve() {
    ll n;
    cin >> n;

    vec<ll> ps;
    ll n3 = n * 3;
    vec<ll> is_p(n3 + 1, 1);
    is_p[0] = is_p[1] = 0;
    for(ll i = 2; i * i <= n3; i++) {
        if(is_p[i]) {
            for(ll j = 2; i * j <= n3; j++) {
                is_p[i * j] = 0;
            }
        }
    }
    rep(i, 2, n + 1) {
        if(is_p[i])
            ps.push_back(i);
    }

    vec<ll> f = is_p;
    f.resize(n + 1);
    auto f3 = convolution_ll(convolution_ll(f, f), f);

    ll ans = 0;
    REP(i, f3.size()) {
        if(is_p[i])
            ans += f3[i];
    }

    for(auto p1 : ps) {
        for(auto p2 : ps) {
            if(is_p[p1 * 2 + p2]) {
                ans -= 3;
            }
        }
    }

    ans /= 6;
    cout << ans << en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // cout << fixed << setprecision(10);

    // ll t;
    // cin >> t;
    // REP(i, t - 1) {
    //     solve();
    // }

    solve();

    return 0;
}
0