QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#584412#9309. GraphqianyueWA 21ms16576kbC++202.2kb2024-09-23 13:59:522024-09-23 13:59:53

Judging History

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

  • [2024-09-23 13:59:53]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:16576kb
  • [2024-09-23 13:59:52]
  • 提交

answer

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

constexpr int mod = 998244353;
// #define int long long
inline int add(int x, int y) {
    return (x + y >= mod ? x + y - mod : x + y);
}
inline int mul(int x, int y) {
    return 1ll * x * y % mod;
}
int qpow(int x, long long n) {
    int y = 1;
    for (; n; n /= 2, x = mul(x, x)) if (n & 1) y = mul(y, x);
    return y;
}

namespace Min25 {
constexpr int maxs = 1000000;
int pri[maxs / 7], lpf[maxs + 1], pcnt;
const int inv2 = qpow(2, mod - 2);

void sieve(int n) {
    for (int i = 2; i <= n; i++) {
        if (!lpf[i]) {
            lpf[i] = ++pcnt;
            pri[lpf[i]] = i;
        }
        for (int j = 1, v; j <= lpf[i] && (v = i * pri[j]) <= n; j++) lpf[v] = j; 
    }
}
long long global_n;
int lim;
int le[maxs + 1], ge[maxs + 1];
#define idx(v) (v <= lim ? le[v] : ge[global_n / v])

long long G[maxs + 1];
long long lis[maxs + 1];
int cnt;

void initG(int n) {
    for (long long i = 1, j, v; i <= n; i = n / j + 1) {
        j = n / i;
        v = j;
        lis[++cnt] = j;
        (j <= lim ? le[j] : ge[global_n / j]) = cnt;
        G[cnt] = v - 1;
    }
}
void calcFprime() {
    for (int k = 1; k <= pcnt; k++) {
        int p = pri[k];
        long long sqrp = 1ll * p * p;
        for (int i = 1; lis[i] >= sqrp; i++) {
            long long v = lis[i] / p;
            int id = idx(v);
            G[i] -= G[id] - (k - 1);
        }
    }
}
void init(long long n) {
    global_n = n;
    lim = sqrt(n);
    sieve(lim + 1000);
    initG(n);
    calcFprime();
}
int get(long long n) {
    return G[idx(n)];
}
}
using Min25::get;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    long long n;
    cin >> n;

    Min25::init(n);

    int res = 1;
    for (long long l = 1, r; l <= n; l = r + 1) {
        r = n / (n / l);
        long long m = n / l;
        long long cnt = get(m) - get(m / 2);
        long long k = 1 + cnt + (m - cnt - 1 > 0);
        int ans = qpow(m % mod, k - 2);
        if (m - cnt - 1 > 0) {
            ans = mul(ans, (m - cnt - 1) % mod);
        }
        res = mul(res, qpow(ans, r - l + 1));
    }
    cout << res;


    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11704kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

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

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

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

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

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

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

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

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 21ms
memory: 16576kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: -100
Wrong Answer
time: 18ms
memory: 14348kb

input:

5120103302

output:

292102619

result:

wrong answer expected '116870489', found '292102619'