結果

問題 No.2902 ZERO!!
ユーザー bortikbortik
提出日時 2024-10-02 03:37:02
言語 C++23(gcc13)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 496 ms / 2,000 ms
コード長 5,160 bytes
コンパイル時間 8,424 ms
コンパイル使用メモリ 415,480 KB
実行使用メモリ 30,444 KB
最終ジャッジ日時 2024-10-02 03:37:19
合計ジャッジ時間 15,628 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
12,136 KB
testcase_01 AC 16 ms
12,268 KB
testcase_02 AC 496 ms
30,444 KB
testcase_03 AC 15 ms
12,136 KB
testcase_04 AC 102 ms
15,880 KB
testcase_05 AC 194 ms
20,608 KB
testcase_06 AC 375 ms
29,396 KB
testcase_07 AC 131 ms
17,200 KB
testcase_08 AC 344 ms
28,212 KB
testcase_09 AC 332 ms
27,784 KB
testcase_10 AC 248 ms
23,888 KB
testcase_11 AC 219 ms
22,164 KB
testcase_12 AC 39 ms
12,844 KB
testcase_13 AC 347 ms
28,180 KB
testcase_14 AC 262 ms
24,372 KB
testcase_15 AC 293 ms
26,120 KB
testcase_16 AC 196 ms
19,892 KB
testcase_17 AC 332 ms
27,716 KB
testcase_18 AC 312 ms
26,740 KB
testcase_19 AC 274 ms
25,288 KB
testcase_20 AC 259 ms
23,400 KB
testcase_21 AC 252 ms
24,284 KB
testcase_22 AC 126 ms
17,832 KB
testcase_23 AC 179 ms
20,340 KB
testcase_24 AC 15 ms
12,136 KB
testcase_25 AC 16 ms
12,268 KB
testcase_26 AC 15 ms
12,140 KB
testcase_27 AC 16 ms
12,272 KB
testcase_28 AC 15 ms
12,272 KB
testcase_29 AC 15 ms
12,140 KB
testcase_30 AC 16 ms
12,144 KB
testcase_31 AC 15 ms
12,268 KB
testcase_32 AC 16 ms
12,144 KB
testcase_33 AC 16 ms
12,272 KB
testcase_34 AC 16 ms
12,264 KB
testcase_35 AC 15 ms
12,140 KB
testcase_36 AC 16 ms
12,140 KB
testcase_37 AC 15 ms
12,144 KB
testcase_38 AC 15 ms
12,272 KB
testcase_39 AC 15 ms
12,136 KB
testcase_40 AC 15 ms
12,140 KB
testcase_41 AC 15 ms
12,140 KB
testcase_42 AC 16 ms
12,272 KB
testcase_43 AC 15 ms
12,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://codeforces.com/blog/entry/96344
#pragma GCC optimize("O3,unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;

#if __cplusplus >= 202002L
using i128 = __int128;
using u128 = unsigned __int128;
using f128 = __float128;
#endif

template<typename T>
bool chmax(T& a, const T& b) {
    bool res = a < b;
    a = max(a, b);
    return res;
}
template<typename T>
bool chmin(T& a, const T& b){
    bool res = a > b;
    a = min(a, b);
    return res;
}

typedef vector<long long> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll>> vll;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;

const int inf = 1000000009;
const ll linf = 4000000000000000009;


// https://trap.jp/post/1224/
template<class... T>
void input(T&... a){
    (cin >> ... >> a);
}

void print(){
    cout << '\n';
}
template<class T, class... Ts>
void print(const T& a, const Ts&... b){
    cout << a;
    (cout << ... << (cout << ' ', b));
    cout << '\n';
}

template <typename T>
T floor(T a, T b) {
  return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
  return floor(x + y - 1, y);
}

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(u32 x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int popcnt(u64 x) { return __builtin_popcountll(x); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }

template<typename T, typename U>
T SUM(const vector<U> &A){
    T ret = 0;
    for (auto &&a: A) ret += a;
    return ret;
}

#define rep1(a)          for(int i = 0; i < a; i++)
#define rep2(i, a)       for(int i = 0; i < a; i++)
#define rep3(i, a, b)    for(int i = a; i < b; i++)
#define rep4(i, a, b, c) for(int i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)

#define rrep(i, a, b)    for(int i = a; i >= b; i--)

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(v) v.begin(), v.end()
//---------------------------------



const ll MOD = 998244353;

vector<pll> factorize(ll n) {
    vector<pll> res;
    for(int i = 2; i*i <= n; i++){
        if(n%i == 0){
            ll cnt = 0;
            while(n%i==0){
                cnt++;
                n /= i;
            }
            res.push_back(mp(i, cnt));
        }
    }
    if(n > 1) res.push_back(mp(n, 1));
    return res;
}

template <typename T>
struct PrimeFact {
    std::vector<T> spf;
    PrimeFact(T N) { init(N); }
    void init(T N) { // 前処理。spf を求める
        spf.assign(N + 1, 0);
        for (T i = 0; i <= N; i++) spf[i] = i;
        for (T i = 2; i * i <= N; i++) {
            if (spf[i] == i) {
                for (T j = i * i; j <= N; j += i) {
                    if (spf[j] == j) {
                        spf[j] = i;
                    }
                }
            }
        }
    }
    std::unordered_map<T, T> get(T n) { // nの素因数分解を求める
        std::unordered_map<T, T> m;
        while (n != 1) {
            m[spf[n]]++;
            n /= spf[n];
        }
        return m;
    }
};


const ll N = 1000000;
vector<ll> lp(N+1);
vector<ll> pr;
void sieve() {
    for (ll i=2; i <= N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;
            pr.push_back(i);
        }
        for (ll j = 0; i * pr[j] <= N; ++j) {
            lp[i * pr[j]] = pr[j];
            if (pr[j] == lp[i]) {
                break;
            }
        }
    }
}

void solve(){
    ll N; cin >> N;
    ll ans = 0;
    vl states(N+1, 1);
    sieve();
    unordered_map<ll, ll> cnt;
    PrimeFact pf(N+1);
    rep(i, 2, N+1) {
        auto facts = pf.get(i);
        for(auto [f, num]: facts) cnt[f] += num;
    }
    for(auto p: pr){
        if(p > N) break;
        ll p_ = p;
        ll num = 0;
        while((N / p) > 0){
            num += N/p;
            p *= p_;
        }
        for(ll i = 1; num / i > 0; i++){
            states[i] *= num / i + 1;
            states[i] %= MOD;
        }
    }
    rep(i, N+1){
        ans += states[i] - 1;
        ans %= MOD;
    }
    print(ans);
}


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


    int t = 1;
    //cin >> t;
    rep(i,0,t) solve();
}
0