結果

問題 No.732 3PrimeCounting
ユーザー てんぷらてんぷら
提出日時 2023-09-22 00:08:38
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 513 ms / 3,000 ms
コード長 1,975 bytes
コンパイル時間 6,821 ms
コンパイル使用メモリ 318,856 KB
実行使用メモリ 17,948 KB
最終ジャッジ日時 2023-09-22 00:08:55
合計ジャッジ時間 15,188 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 7 ms
4,380 KB
testcase_22 AC 7 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 14 ms
4,380 KB
testcase_26 AC 11 ms
4,380 KB
testcase_27 AC 4 ms
4,380 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 6 ms
4,380 KB
testcase_30 AC 6 ms
4,376 KB
testcase_31 AC 7 ms
4,376 KB
testcase_32 AC 12 ms
4,380 KB
testcase_33 AC 12 ms
4,380 KB
testcase_34 AC 12 ms
4,376 KB
testcase_35 AC 10 ms
4,380 KB
testcase_36 AC 10 ms
4,380 KB
testcase_37 AC 3 ms
4,376 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 10 ms
4,380 KB
testcase_40 AC 8 ms
4,380 KB
testcase_41 AC 8 ms
4,380 KB
testcase_42 AC 7 ms
4,380 KB
testcase_43 AC 7 ms
4,376 KB
testcase_44 AC 7 ms
4,380 KB
testcase_45 AC 4 ms
4,380 KB
testcase_46 AC 4 ms
4,380 KB
testcase_47 AC 5 ms
4,376 KB
testcase_48 AC 14 ms
4,380 KB
testcase_49 AC 14 ms
4,376 KB
testcase_50 AC 7 ms
4,376 KB
testcase_51 AC 7 ms
4,376 KB
testcase_52 AC 4 ms
4,376 KB
testcase_53 AC 31 ms
4,768 KB
testcase_54 AC 231 ms
11,520 KB
testcase_55 AC 241 ms
11,732 KB
testcase_56 AC 233 ms
11,580 KB
testcase_57 AC 68 ms
6,276 KB
testcase_58 AC 68 ms
6,060 KB
testcase_59 AC 33 ms
5,000 KB
testcase_60 AC 105 ms
7,388 KB
testcase_61 AC 105 ms
7,376 KB
testcase_62 AC 248 ms
12,656 KB
testcase_63 AC 146 ms
8,708 KB
testcase_64 AC 119 ms
7,708 KB
testcase_65 AC 116 ms
7,732 KB
testcase_66 AC 2 ms
4,380 KB
testcase_67 AC 2 ms
4,380 KB
testcase_68 AC 249 ms
12,124 KB
testcase_69 AC 247 ms
12,172 KB
testcase_70 AC 239 ms
11,632 KB
testcase_71 AC 260 ms
11,732 KB
testcase_72 AC 140 ms
8,680 KB
testcase_73 AC 318 ms
16,020 KB
testcase_74 AC 318 ms
15,860 KB
testcase_75 AC 14 ms
4,376 KB
testcase_76 AC 253 ms
11,500 KB
testcase_77 AC 69 ms
6,608 KB
testcase_78 AC 296 ms
14,548 KB
testcase_79 AC 245 ms
11,872 KB
testcase_80 AC 289 ms
12,936 KB
testcase_81 AC 253 ms
11,588 KB
testcase_82 AC 4 ms
4,376 KB
testcase_83 AC 70 ms
6,324 KB
testcase_84 AC 98 ms
6,388 KB
testcase_85 AC 223 ms
10,692 KB
testcase_86 AC 291 ms
13,716 KB
testcase_87 AC 513 ms
17,948 KB
testcase_88 AC 488 ms
17,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REP(i, m, n) for(ll i = (ll)(m); i < (ll)(n); i++)
using namespace std;
using namespace atcoder;
using mint = modint998244353;

tuple<vector<ll>, vector<ll>> solve(int l, int r, vector<int> &f) {
    if(r - l == 1) {
        return {{0}, {0}};
    }
    int m = (l + r) / 2;
    auto [l2, l3] = solve(l, m, f);
    auto [r2, r3] = solve(m, r, f);
    vector<ll> a2(2 * (r - l) - 1), a3(3 * (r - l) - 2);
    vector<ll> fl(m - l), fr(r - m);
    rep(i, m - l) {
        fl[i] = f[l + i];
    }
    rep(i, r - m) {
        fr[i] = f[m + i];
    }
    {
        auto n2 = convolution(fl, fr);
        rep(i, n2.size()) {
            a2[m - l + i] += n2[i];
        }
        rep(i, l2.size()) {
            a2[i] += l2[i];
        }
        rep(i, r2.size()) {
            a2[2 * (m - l) + i] += r2[i];
        }
    }
    {
        auto n2_1 = convolution(l2, fr);
        auto n1_2 = convolution(fl, r2);
        rep(i, n2_1.size()) {
            a3[m - l + i] += n2_1[i];
        }
        rep(i, n1_2.size()) {
            a3[2 * (m - l) + i] += n1_2[i];
        }
        rep(i, l3.size()) {
            a3[i] += l3[i];
        }
        rep(i, r3.size()) {
            a3[3 * (m - l) + i] += r3[i];
        }
    }
    return {a2, a3};
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> is_prime(3 * n + 1, 1);
    is_prime[0] = is_prime[1] = 0;
    for(int i = 2; i <= 3 * n; i++) {
        if(!is_prime[i]) {
            continue;
        }
        for(int j = 2 * i; j <= 3 * n; j += i) {
            is_prime[j] = 0;
        }
    }
    vector<int> f(n + 1);
    rep(i, n + 1) f[i] = is_prime[i];
    auto ret = get<1>(solve(0, n + 1, f));
    ll ans = 0;
    rep(i, 3 * n + 1) {
        ans += is_prime[i] ? ret[i] : 0;
    }
    cout << ans << endl;

    return 0;
}
0