QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#638015#8761. 另一个计数问题ricofx#AC ✓1601ms49436kbC++204.1kb2024-10-13 14:39:152024-10-13 14:39:21

Judging History

This is the latest submission verdict.

  • [2024-10-13 14:39:21]
  • Judged
  • Verdict: AC
  • Time: 1601ms
  • Memory: 49436kb
  • [2024-10-13 14:39:15]
  • Submitted

answer

//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 998244353;
const int N = 1e6  + 5;

int fpow(int a, int b) {
    int res = 1;
    for (; b; b >>= 1, a = a * 1ll * a % mod) if (b & 1) res = res * 1ll * a % mod;
    return res;
}
int sum(int x) {
    static int i2 = (mod + 1) >> 1;
    return x * 1ll * (x + 1) % mod * i2 % mod;
}
int sum2(int x) {
    static int i6 = fpow(6, mod - 2);
    return x * 1ll * (x + 1) % mod * (x + x + 1) % mod * i6 % mod;
}
int sum3(int x) {
    static int i2 = (mod + 1) >> 1;
    int r = x * 1ll * (x + 1) % mod * i2 % mod;
    return r * 1ll * r % mod;
} 
int sum3(int l, int r) {
    return (sum3(r) + mod - sum3(l - 1)) % mod;
}
int sum2(int l, int r) {
    return (sum2(r) + mod - sum2(l - 1)) % mod;
}
namespace Min25 {
    int g1[N], g2[N], g3[N];
    int id1[N], id2[N], w[N], tot, sqr;
    int vis[N], pcnt, p[N], sup[N], sup2[N], sup3[N];
    void init(int n) {
        pcnt = 0;
        for (int i = 2; i <= n; i++) {
            if (!vis[i]){
                p[++pcnt] = i;
                sup[pcnt] = (sup[pcnt - 1] + i) % mod;
                sup2[pcnt] = (sup2[pcnt - 1] + i * 1ll * i % mod) % mod;
                sup3[pcnt] = (sup3[pcnt - 1] + i * 1ll * i % mod * i % mod) % mod;
            }
            for (int j = 1; j <= pcnt && p[j] * 1ll * i <= n; ++j) {
                int v = p[j] * i;
                vis[v] = 1;
                if (i % p[j] == 0) break;
            }
        }
    }
    void solve(ll n) {
        tot = 0;
        int sqr = sqrt(n + 0.5) + 1;
        init(sqr);
        for (ll i = 1, j; i <= n; i = j + 1) {
            j = n / (n / i);
            w[++tot] = n / i;
            g1[tot] = (sum(w[tot] % mod) + mod - 1) % mod;
            g2[tot] = (sum2(w[tot] % mod) + mod - 1) % mod;
            g3[tot] = (sum3(w[tot] % mod) + mod - 1) % mod;
            if (w[tot] <= sqr) id1[w[tot]] = tot;
            else id2[j] = tot;
        }
        for (int j = 1; j <= pcnt; j++) {
            for (int i = 1; i <= tot && p[j] * p[j] <= w[i]; i++) {
                ll t = w[i] / p[j];
                int k;
                if (t <= sqr) k = id1[t];
                else k = id2[n / t];
                g1[i] += (mod - p[j] * ((g1[k] + mod - sup[j - 1]) % mod) % mod) % mod;
                g1[i] %= mod;
                g2[i] += (mod - p[j] * p[j] % mod * ((g2[k] + mod - sup2[j - 1]) % mod) % mod) % mod;
                g2[i] %= mod;
            }
        }
    }
}
int check(int x) {
    for (int i = 2; i * i <= x; i++) if (x % i == 0) return false;
    return true;
}
void MAIN() {
    ll n;
    cin >> n;
    const int i2 = (mod + 1) >> 1;
    ll res = sum3(2, n % mod) * 1ll * i2 % mod;
    res = (res + mod - sum2(2, n % mod) * 1ll * i2 % mod) % mod;
    res = (res + mod - (sum(n % mod) + mod - 1) % mod) % mod;
    Min25::solve(n);
    int HS = (sum(n % mod) + mod - 1 - Min25::g1[1]) % mod;
    int SS = (sum(n % mod) + mod - 1) % mod;
    //cout << HS << ' ' << Min25::g1[1] << '\n';
    int S1 = Min25::g1[1];
    int S2 = Min25::g2[1];
    Min25::solve(n / 2);
    HS = (HS + Min25::g1[1]) % mod;
    S2 = (S2 + mod - Min25::g2[1]) % mod;
    S1 = (S1 + mod - Min25::g1[1]) % mod;
    int t = (S1 * SS % mod + S1 * HS % mod + mod - S2) % mod * i2 % mod;
    cout << (res + mod - t) % mod << '\n';
}

signed main() {
#ifdef LOCAL
    auto start = chrono::steady_clock::now();
    freopen("miku.in", "r", stdin);
    freopen("miku.out", "w", stdout);
#endif
    ios::sync_with_stdio(0); cin.tie(0);
    int T = 1;
    // cin >> T;
    while (T--) MAIN();
#ifdef LOCAL
    auto end = chrono::steady_clock::now();
    cout << "\nqwq: " <<  chrono::duration_cast<chrono::milliseconds>(end - start).count() << "ms\n";
#endif
    return 0;
}

详细

Test #1:

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

input:

4

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: 0
Accepted
time: 3ms
memory: 20056kb

input:

5

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

input:

6

output:

80

result:

ok 1 number(s): "80"

Test #4:

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

input:

7

output:

80

result:

ok 1 number(s): "80"

Test #5:

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

input:

8

output:

200

result:

ok 1 number(s): "200"

Test #6:

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

input:

9

output:

407

result:

ok 1 number(s): "407"

Test #7:

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

input:

10

output:

937

result:

ok 1 number(s): "937"

Test #8:

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

input:

79

output:

3224298

result:

ok 1 number(s): "3224298"

Test #9:

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

input:

123

output:

21077222

result:

ok 1 number(s): "21077222"

Test #10:

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

input:

158

output:

57411585

result:

ok 1 number(s): "57411585"

Test #11:

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

input:

285

output:

605750829

result:

ok 1 number(s): "605750829"

Test #12:

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

input:

355

output:

509863120

result:

ok 1 number(s): "509863120"

Test #13:

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

input:

484

output:

311440260

result:

ok 1 number(s): "311440260"

Test #14:

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

input:

520

output:

102191845

result:

ok 1 number(s): "102191845"

Test #15:

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

input:

706

output:

300787918

result:

ok 1 number(s): "300787918"

Test #16:

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

input:

747

output:

505062591

result:

ok 1 number(s): "505062591"

Test #17:

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

input:

784

output:

181810798

result:

ok 1 number(s): "181810798"

Test #18:

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

input:

76879

output:

716166793

result:

ok 1 number(s): "716166793"

Test #19:

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

input:

209295

output:

753032272

result:

ok 1 number(s): "753032272"

Test #20:

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

input:

220895

output:

874612082

result:

ok 1 number(s): "874612082"

Test #21:

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

input:

243390

output:

68635874

result:

ok 1 number(s): "68635874"

Test #22:

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

input:

414767

output:

862578797

result:

ok 1 number(s): "862578797"

Test #23:

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

input:

431662

output:

231728766

result:

ok 1 number(s): "231728766"

Test #24:

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

input:

521130

output:

106207351

result:

ok 1 number(s): "106207351"

Test #25:

score: 0
Accepted
time: 3ms
memory: 20080kb

input:

668419

output:

580625063

result:

ok 1 number(s): "580625063"

Test #26:

score: 0
Accepted
time: 3ms
memory: 19980kb

input:

700378

output:

790849562

result:

ok 1 number(s): "790849562"

Test #27:

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

input:

965876

output:

856082142

result:

ok 1 number(s): "856082142"

Test #28:

score: 0
Accepted
time: 65ms
memory: 24352kb

input:

998244350

output:

539142456

result:

ok 1 number(s): "539142456"

Test #29:

score: 0
Accepted
time: 61ms
memory: 22256kb

input:

998244351

output:

730264865

result:

ok 1 number(s): "730264865"

Test #30:

score: 0
Accepted
time: 61ms
memory: 22116kb

input:

998244352

output:

326703895

result:

ok 1 number(s): "326703895"

Test #31:

score: 0
Accepted
time: 57ms
memory: 22300kb

input:

998244353

output:

326703895

result:

ok 1 number(s): "326703895"

Test #32:

score: 0
Accepted
time: 62ms
memory: 24096kb

input:

998244354

output:

730264864

result:

ok 1 number(s): "730264864"

Test #33:

score: 0
Accepted
time: 57ms
memory: 22096kb

input:

998244355

output:

539142451

result:

ok 1 number(s): "539142451"

Test #34:

score: 0
Accepted
time: 61ms
memory: 24208kb

input:

998244356

output:

751581014

result:

ok 1 number(s): "751581014"

Test #35:

score: 0
Accepted
time: 106ms
memory: 22332kb

input:

2165916141

output:

216013547

result:

ok 1 number(s): "216013547"

Test #36:

score: 0
Accepted
time: 155ms
memory: 28388kb

input:

3550627266

output:

318019384

result:

ok 1 number(s): "318019384"

Test #37:

score: 0
Accepted
time: 350ms
memory: 30504kb

input:

11640239920

output:

137498099

result:

ok 1 number(s): "137498099"

Test #38:

score: 0
Accepted
time: 446ms
memory: 32676kb

input:

16191777349

output:

991399721

result:

ok 1 number(s): "991399721"

Test #39:

score: 0
Accepted
time: 710ms
memory: 40928kb

input:

31326230483

output:

99981147

result:

ok 1 number(s): "99981147"

Test #40:

score: 0
Accepted
time: 720ms
memory: 38852kb

input:

32810385543

output:

284259680

result:

ok 1 number(s): "284259680"

Test #41:

score: 0
Accepted
time: 795ms
memory: 36780kb

input:

37368395332

output:

511468046

result:

ok 1 number(s): "511468046"

Test #42:

score: 0
Accepted
time: 832ms
memory: 40920kb

input:

40002331093

output:

282851705

result:

ok 1 number(s): "282851705"

Test #43:

score: 0
Accepted
time: 1406ms
memory: 47304kb

input:

82884464396

output:

767050832

result:

ok 1 number(s): "767050832"

Test #44:

score: 0
Accepted
time: 1555ms
memory: 45380kb

input:

96506992785

output:

31413975

result:

ok 1 number(s): "31413975"

Test #45:

score: 0
Accepted
time: 1595ms
memory: 47012kb

input:

99999999995

output:

456189842

result:

ok 1 number(s): "456189842"

Test #46:

score: 0
Accepted
time: 1589ms
memory: 47296kb

input:

99999999996

output:

516138273

result:

ok 1 number(s): "516138273"

Test #47:

score: 0
Accepted
time: 1599ms
memory: 49436kb

input:

99999999997

output:

136420410

result:

ok 1 number(s): "136420410"

Test #48:

score: 0
Accepted
time: 1588ms
memory: 49296kb

input:

99999999998

output:

841974696

result:

ok 1 number(s): "841974696"

Test #49:

score: 0
Accepted
time: 1601ms
memory: 49224kb

input:

99999999999

output:

164762165

result:

ok 1 number(s): "164762165"

Test #50:

score: 0
Accepted
time: 1593ms
memory: 49356kb

input:

100000000000

output:

627965619

result:

ok 1 number(s): "627965619"