QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#575395#8761. 另一个计数问题caojcWA 38ms5728kbC++203.8kb2024-09-19 13:43:412024-09-19 13:43:41

Judging History

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

  • [2024-09-19 13:43:41]
  • 评测
  • 测评结果:WA
  • 用时:38ms
  • 内存:5728kb
  • [2024-09-19 13:43:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int, int>

#define db(args...) { \
     string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
     stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cout << '\n';}
void err(istream_iterator<string> it){}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << ' ';
    err(++it, args...);
}


const int mod = 998244353;
ll ksm(ll a, ll b = mod - 2) {
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod, b /= 2;
    }
    return res;
}
ll i2, i6;
ll s1(ll n) {
    return (1 + n) * n % mod * i2 % mod;
}
ll s1(ll l, ll r) {
    return (s1(r) - s1(l - 1) + mod) % mod;
}
ll s2(ll n) {
    return n * (n + 1) % mod * (2 * n + 1) % mod * i6 % mod;
}
ll s2(ll l, ll r) {
    return (s2(r) - s2(l - 1) + mod) % mod;
}



/*
min25筛第一部分,求质数的多项式和。
 */
vector<int> visi, pri; int cpri;
void init(int N) {
    N++; cpri = 0;
    visi.assign(N, 0), pri.assign(N, 0);
    for (int i = 2; i < N; i++) {
        if (!visi[i]) {
            visi[i] = i;
            pri[++cpri] = i;
        }
        for (int j = 1; j <= cpri; j++) {
            int id = pri[j] * i;
            if (id >= N) break;
            visi[id] = pri[j];
            if (i % pri[j] == 0) break;
        }
    }
}
struct min25 {
    // 幂次k=1
    ll sn, n;
    vector<int> id;
    vector<ll> g;
    int getid(ll x) {
        if (x <= sn) return x;
        return id[n / x];
    }
    min25(ll N, int k) {
        n = N;
        sn = sqrt((long double)n);
        init(2 * sn + 10); // todo

        id.assign(sn + 1, 0);
        g.assign(sn * 2 + 1, 0);
        vector<ll> big(sn * 2 + 1), G(sn + 1);
        
        for (int i = 2; i <= sn; i++) {
            G[i] = G[i - 1] + (visi[i] == i) * ksm(i, k);
            g[i] %= mod;
        }
        for (int i = 1; i <= sn; i++) {
            id[i] = 2 * sn + 1 - i;
            big[i] = i, big[id[i]] = n / i;
        }

        for (int i = 1; i <= sn * 2; i++) {
            if (k == 0) g[i] = big[i] - 1; // todo 除了1所有数的k次方前缀和
            if (k == 1) g[i] = (s1(big[i]) - 1 + mod) % mod;
            if (k == 2) g[i] = (s2(big[i]) - 1 + mod) % mod;
        }
        for (int j = 1, beg = 1; pri[j] <= sn; j++) {
            while (j > 1 && beg <= sn * 2 && pri[j] * 1ll * pri[j] > big[beg]) beg++;
            for (int i = sn * 2; i >= beg; i--) {
                ll v = ksm(pri[j], k); // todo pri[j] ^ k
                g[i] = g[i] - v * (g[getid(big[i] / pri[j])] - G[pri[j - 1]]);
                g[i] = (g[i] % mod + mod) % mod;
            }
        }
    }
    ll get(ll n) {
        return g[getid(n)];
    }
};
void solve() {
    i2 = ksm(2), i6 = ksm(6);

    ll n;
    cin >> n;

    ll ans1 = 0;
    ans1 = (s1(2, n / 2) * s1(2, n / 2) % mod - s2(2, n / 2) + mod) % mod * i2 % mod;

    min25 m1(n, 1);
    min25 m2(n, 2);

    ll v1 = s1(2, n / 2), v2 = (s1(n / 2 + 1, n) - (m1.get(n) - m1.get(n / 2)));
    v2 = (v2 % mod + mod) % mod;
    ll ans2 = v1 * v2;
    ans2 = (ans2 % mod + mod) % mod;

    ll v = s1(n / 2 + 1, n) - (m1.get(n) - m1.get(n / 2));
    v = (v % mod + mod) % mod;
    ll ans3 = (v * v - (s2(n / 2 + 1, n) - m2.get(n) + m2.get(n / 2)));
    ans3 = (ans3 % mod + mod) % mod;
    ans3 = ans3 * i2 % mod;


    ll ans = ans1 + ans2 + ans3;
    ans = (ans % mod + mod) % mod;
    cout << ans << '\n';
}
signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int t = 1; 
    // cin >> t;
    while (t--) solve();
    return 0;
}
/*
g++ 1.cpp -std=c++20 -o 1 && ./1 < in.txt > out.txt
*/

详细

Test #1:

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

input:

4

output:

8

result:

ok 1 number(s): "8"

Test #2:

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

input:

5

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

input:

6

output:

80

result:

ok 1 number(s): "80"

Test #4:

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

input:

7

output:

80

result:

ok 1 number(s): "80"

Test #5:

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

input:

8

output:

200

result:

ok 1 number(s): "200"

Test #6:

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

input:

9

output:

407

result:

ok 1 number(s): "407"

Test #7:

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

input:

10

output:

937

result:

ok 1 number(s): "937"

Test #8:

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

input:

79

output:

3224298

result:

ok 1 number(s): "3224298"

Test #9:

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

input:

123

output:

21077222

result:

ok 1 number(s): "21077222"

Test #10:

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

input:

158

output:

57411585

result:

ok 1 number(s): "57411585"

Test #11:

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

input:

285

output:

605750829

result:

ok 1 number(s): "605750829"

Test #12:

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

input:

355

output:

509863120

result:

ok 1 number(s): "509863120"

Test #13:

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

input:

484

output:

311440260

result:

ok 1 number(s): "311440260"

Test #14:

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

input:

520

output:

102191845

result:

ok 1 number(s): "102191845"

Test #15:

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

input:

706

output:

300787918

result:

ok 1 number(s): "300787918"

Test #16:

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

input:

747

output:

505062591

result:

ok 1 number(s): "505062591"

Test #17:

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

input:

784

output:

181810798

result:

ok 1 number(s): "181810798"

Test #18:

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

input:

76879

output:

716166793

result:

ok 1 number(s): "716166793"

Test #19:

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

input:

209295

output:

753032272

result:

ok 1 number(s): "753032272"

Test #20:

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

input:

220895

output:

874612082

result:

ok 1 number(s): "874612082"

Test #21:

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

input:

243390

output:

68635874

result:

ok 1 number(s): "68635874"

Test #22:

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

input:

414767

output:

862578797

result:

ok 1 number(s): "862578797"

Test #23:

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

input:

431662

output:

231728766

result:

ok 1 number(s): "231728766"

Test #24:

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

input:

521130

output:

106207351

result:

ok 1 number(s): "106207351"

Test #25:

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

input:

668419

output:

580625063

result:

ok 1 number(s): "580625063"

Test #26:

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

input:

700378

output:

790849562

result:

ok 1 number(s): "790849562"

Test #27:

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

input:

965876

output:

856082142

result:

ok 1 number(s): "856082142"

Test #28:

score: -100
Wrong Answer
time: 38ms
memory: 5728kb

input:

998244350

output:

661423330

result:

wrong answer 1st numbers differ - expected: '539142456', found: '661423330'