QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#649616#9309. GraphfosovRE 95ms14480kbC++143.0kb2024-10-18 03:36:022024-10-18 03:36:04

Judging History

你现在查看的是最新测评结果

  • [2024-10-18 03:36:04]
  • 评测
  • 测评结果:RE
  • 用时:95ms
  • 内存:14480kb
  • [2024-10-18 03:36:02]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;

#define ll long long 
#define INF 0x3f3f3f3f
#define LNF 0x3f3f3f3f3f3f3f3fll
#define MOD 998244353

#define pii pair<int, int>

template<int M>
struct modint {
    int val;

    modint(): val(0) {};
    modint(ll val): val(val % M) {};

    modint operator+(modint o) {
        return modint(((ll) val + o.val) % M);
    }
    modint operator-(modint o) {
        return modint(((ll) val - o.val + M) % M);
    }
    modint operator*(modint o) {
        return modint((ll) val * o.val % M);
    }
    modint operator/(modint o) {
        return *this * o.pow(M-2);
    }

    modint pow(ll p) {
        modint b = *this, c = modint(1);
        for (; p; b=b*b, p>>=1) if (p&1) c=c*b;
        return c;
    }
};

template<int M>
ostream& operator<<(ostream& os, const modint<M>& s) {
    return os << s.val;
}

#define mint modint<MOD>

struct min25 {
    static const int N = 1000010;
    ll n, m, s;
    ll bk[N], g[N];
    int pc, p[N], ip[N];

    static ll isqrt(ll x) {
        ll l = 1, r = x;
        while (l < r) {
            ll m = (l + r) >> 1;
            if (m * m < x) {
                l = m + 1;
            } else {
                r = m;
            }
        }
        return r - (r * r > x);
    }

    void linear_sieve(int x) {
        pc = p[0] = 1;
        for (int i = 1; i < x; ++ i) ip[i] = 1;
        for (int i = 2; i < x; ++ i) {
            if (ip[i]) p[pc ++] = i;
            for (int j = 1; j < pc && (ll) i * p[j] < x; ++ j) {
                ip[i * p[j]] = 0;
                if (i % p[j] == 0) break;
            }
        }
    }
    
    int get_id(ll x) {
        return x <= s ? x - 1 : m - n / x;
    }

    void init(ll n) {
        this->n = n;
        m = 0;
        s = isqrt(n);

        linear_sieve(s + 1);
        
        for (int i = 1; i <= s; ++ i) bk[m ++] = i;
        for (int i = s; i >= 1; -- i) if (n / i > s) bk[m ++] = n / i;

        for (int i = 0; i < m; ++ i) g[i] = bk[i] - 1;
        for (int i = 1, bi = 0; i < pc; ++ i) {
            while (1ll * p[i] * p[i] > bk[bi]) ++ bi;
            for (int j = m-1; j >= bi; -- j) {
                g[j] = g[j] - 1ll * (g[get_id(bk[j] / p[i])] - g[get_id(p[i-1])]);
            }
        }
    }

    int cnt_prime(ll x) {
        if (x == 0) return 0;
        assert(bk[get_id(x)] == x);
        return g[get_id(x)];
    }
} sieve;

int main() {
#ifdef TEST
    freopen("zz.in", "r+", stdin);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n; cin >> n;

    sieve.init(n);

    ll l = 1;
    mint res = mint(1);
    while (l <= n) {
        ll r = n / (n / l);
        ll m = n / l;

        int np = sieve.cnt_prime(m) - sieve.cnt_prime(m / 2);
        int k = 1 + np + (m - 1 - np != 0);
        mint mu = mint(max(m - 1 - np, 1ll));
        mint cur = mu * mint(m).pow(max(0, k - 2));
        res = res * cur.pow(r - l + 1);

        l = r+1;
    }

    cout << res << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 9732kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 1ms
memory: 9872kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 1ms
memory: 9728kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 1ms
memory: 9852kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 0ms
memory: 9744kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 0ms
memory: 9812kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 1ms
memory: 9812kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 1ms
memory: 9820kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 1ms
memory: 9748kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 2ms
memory: 9852kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 4ms
memory: 9968kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 11ms
memory: 12308kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 11ms
memory: 10356kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 24ms
memory: 14076kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 42ms
memory: 12896kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 95ms
memory: 14480kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: -100
Runtime Error

input:

52500109238

output:


result: