QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#649618#9309. GraphfosovAC ✓295ms21632kbC++143.0kb2024-10-18 03:45:462024-10-18 03:45:47

Judging History

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

  • [2024-10-18 03:45:47]
  • 评测
  • 测评结果:AC
  • 用时:295ms
  • 内存:21632kb
  • [2024-10-18 03:45:46]
  • 提交

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 = 2000010;
    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) / 2;
            if (m < x / m) {
                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';
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

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

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 5ms
memory: 9960kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 16ms
memory: 10364kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 12ms
memory: 14184kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 20ms
memory: 11992kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

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

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 96ms
memory: 14952kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 191ms
memory: 18108kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 259ms
memory: 21512kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 290ms
memory: 21556kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 290ms
memory: 21632kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 295ms
memory: 21396kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed