結果

問題 No.732 3PrimeCounting
ユーザー てんぷらてんぷら
提出日時 2023-09-22 00:06:21
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,946 ms / 3,000 ms
コード長 1,984 bytes
コンパイル時間 5,956 ms
コンパイル使用メモリ 311,528 KB
実行使用メモリ 20,320 KB
最終ジャッジ日時 2023-09-22 00:06:59
合計ジャッジ時間 35,228 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 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 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 6 ms
4,380 KB
testcase_21 AC 22 ms
4,376 KB
testcase_22 AC 22 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 48 ms
4,380 KB
testcase_26 AC 36 ms
4,376 KB
testcase_27 AC 9 ms
4,376 KB
testcase_28 AC 8 ms
4,376 KB
testcase_29 AC 18 ms
4,376 KB
testcase_30 AC 18 ms
4,376 KB
testcase_31 AC 24 ms
4,376 KB
testcase_32 AC 39 ms
4,376 KB
testcase_33 AC 39 ms
4,376 KB
testcase_34 AC 39 ms
4,376 KB
testcase_35 AC 33 ms
4,376 KB
testcase_36 AC 33 ms
4,380 KB
testcase_37 AC 5 ms
4,376 KB
testcase_38 AC 4 ms
4,380 KB
testcase_39 AC 34 ms
4,376 KB
testcase_40 AC 24 ms
4,380 KB
testcase_41 AC 25 ms
4,376 KB
testcase_42 AC 25 ms
4,376 KB
testcase_43 AC 21 ms
4,376 KB
testcase_44 AC 20 ms
4,376 KB
testcase_45 AC 10 ms
4,380 KB
testcase_46 AC 10 ms
4,380 KB
testcase_47 AC 16 ms
4,380 KB
testcase_48 AC 49 ms
4,380 KB
testcase_49 AC 49 ms
4,380 KB
testcase_50 AC 22 ms
4,380 KB
testcase_51 AC 23 ms
4,380 KB
testcase_52 AC 9 ms
4,376 KB
testcase_53 AC 109 ms
4,852 KB
testcase_54 AC 931 ms
12,560 KB
testcase_55 AC 891 ms
12,604 KB
testcase_56 AC 892 ms
12,560 KB
testcase_57 AC 248 ms
6,900 KB
testcase_58 AC 250 ms
6,704 KB
testcase_59 AC 114 ms
5,032 KB
testcase_60 AC 398 ms
7,772 KB
testcase_61 AC 397 ms
7,764 KB
testcase_62 AC 975 ms
14,108 KB
testcase_63 AC 528 ms
10,144 KB
testcase_64 AC 461 ms
8,260 KB
testcase_65 AC 430 ms
8,308 KB
testcase_66 AC 2 ms
4,376 KB
testcase_67 AC 2 ms
4,376 KB
testcase_68 AC 963 ms
13,136 KB
testcase_69 AC 966 ms
13,080 KB
testcase_70 AC 898 ms
12,680 KB
testcase_71 AC 899 ms
12,640 KB
testcase_72 AC 547 ms
10,096 KB
testcase_73 AC 1,259 ms
17,188 KB
testcase_74 AC 1,258 ms
17,220 KB
testcase_75 AC 46 ms
4,380 KB
testcase_76 AC 926 ms
13,200 KB
testcase_77 AC 252 ms
7,128 KB
testcase_78 AC 1,178 ms
15,324 KB
testcase_79 AC 929 ms
13,300 KB
testcase_80 AC 1,109 ms
15,572 KB
testcase_81 AC 934 ms
13,516 KB
testcase_82 AC 8 ms
4,380 KB
testcase_83 AC 247 ms
6,716 KB
testcase_84 AC 397 ms
7,068 KB
testcase_85 AC 857 ms
11,856 KB
testcase_86 AC 1,136 ms
16,052 KB
testcase_87 AC 1,945 ms
20,320 KB
testcase_88 AC 1,946 ms
20,092 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_ll(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_ll(l2, fr);
        auto n1_2 = convolution_ll(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