QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#606465#8761. 另一个计数问题AAA___AC ✓1677ms104588kbC++204.0kb2024-10-03 09:16:272024-10-03 09:16:27

Judging History

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

  • [2024-10-03 09:16:27]
  • 评测
  • 测评结果:AC
  • 用时:1677ms
  • 内存:104588kb
  • [2024-10-03 09:16:27]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<stack>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<map>
#include<string>
#include<vector>
#include<array>
#include<functional>
#define int long long
using namespace std;
typedef long long ll;
ll highbit(ll x){
    ll ans=2;
    int num=1;
    while(x){
        x>>=2;
        ans<<=2;
        num++;
    }
    return num;
}
ll lowbit(ll x){
    return x&(-x);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a>b?b:a;
}
ll gcd(ll x,ll y)
{
    if(y==1)
        return x;
    return gcd(y,x%y);
}
const int N = 1000010;
const ll mod=998244353;
const ll in2=499122177,in6=166374059;
ll md(ll x){
    return x%mod;
}
struct MIN1{
    ll prime[N], id1[N], id2[N], flag[N], ncnt, m;
    ll g[N], sum[N], a[N], T;
    ll n;
    ll ID(ll x) {
        return x <= T ? id1[x] : id2[n / x];
    }
    ll calc(ll x) {
        x%=mod;
        ll ans=md(x*(x+1))*in2;
        ans--;
        ans%=mod;
        return ans;
    }
    ll init(ll n){
        T = sqrt(n+0.5);
        for (int i = 2; i <= T; i++) {
            if (!flag[i]) prime[++ncnt] = i, sum[ncnt] = md(sum[ncnt - 1] + i),sum[ncnt]=md(sum[ncnt]);
            
            for (int j = 1; j <= ncnt && i * prime[j] <= T; j++) {
                flag[i * prime[j]] = 1;
                if (i % prime[j] == 0) break;
            }
        }
        for (ll l = 1; l <= n; l = n / (n / l) + 1) {
            a[++m] = n / l;
            if (a[m] <= T) id1[a[m]] = m; else id2[n / a[m]] = m;
            g[m] = calc(a[m]);
        }
        for (ll i = 1; i <= ncnt; i++)
            for (ll j = 1; j <= m && (ll)prime[i] * prime[i] <= a[j]; j++){
                g[j] = g[j] 
                - ((ll)prime[i] * ((g[ID(a[j] / prime[i])] - sum[i - 1]+mod)%mod))%mod;
            }

        return 0;
    }
    ll solve(ll x){
        if(x<=1){return x;}
        return n=x,init(n),g[ID(n)];
    }
}m11,m12;
struct MIN2{
    ll id1[N], id2[N], ncnt, m,prime[N],flag[N];
    ll g[N], sum[N], a[N], T;
    ll n;
    ll ID(ll x) {
        return x <= T ? id1[x] : id2[n / x];
    }
    ll calc(ll x) {
        x%=mod;
        ll ans= (md(md(x*(x+1))*(2*x+1))*in6);
        return ans-1;
    }
    ll init(ll n){
        T = sqrt(n + 0.5);
        for (int i = 2; i <= T; i++) {
            if (!flag[i]) prime[++ncnt] = i, sum[ncnt] = sum[ncnt - 1] + md(i*i),sum[ncnt]=md(sum[ncnt]);
            for (int j = 1; j <= ncnt && i * prime[j] <= T; j++) {
                flag[i * prime[j]] = 1;
                if (i % prime[j] == 0) break;
            }
        }
        for (ll l = 1; l <= n; l = n / (n / l) + 1) {
            a[++m] = n / l;
            if (a[m] <= T) id1[a[m]] = m; else id2[n / a[m]] = m;
            g[m] = calc(a[m]);
        }
        for (ll i = 1; i <= ncnt; i++)
            for (ll j = 1; j <= m && prime[i] * prime[i] <= a[j]; j++){
                g[j] = g[j] - 
                md(md(prime[i]*prime[i]) * md(g[ID(a[j] / prime[i])] - sum[i - 1])),g[j]=(g[j]%mod+mod)%mod;
            }
        return 0;
    }
    ll solve(ll x){
        if(x<=1){return x;}
        return n=x,init(n),g[ID(n)];
    }
}m21,m22;
signed main(void){
    unsigned int t;
    //freopen("input.in","r",stdin);
    ll n;
    cin>>n;
    ll nk=n;
    if(n%2==0){
        nk=n+1;
    }else{
        nk=n;
    }
    ll pre1=m11.solve(n)-m12.solve((nk)/2);
    ll pre2=m21.solve(n)-m22.solve((nk)/2);
    pre1=md(md(pre1)+mod);
    pre2=md(md(pre2)+mod);
    ll ans=0;
    ll k=n%mod;
    ll buff=md(md(md((2+k)*(k-1))*in2)*md(md((2+k)*(k-1))*in2));
    buff-=md(md(md(k*md(k+1))*md(2*k+1))*in6);
    buff=md(md(buff)+mod);
    buff++;
    buff*=in2;
    buff%=mod;
    ans=md( md(md(md((2+k)*(k-1))*in2)*pre1)-pre2-md(md((pre1*pre1)-pre2)*in2)+mod );
    ans=(buff-ans+mod)%mod;
    cout<<ans<<endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4

output:

8

result:

ok 1 number(s): "8"

Test #2:

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

input:

5

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

input:

6

output:

80

result:

ok 1 number(s): "80"

Test #4:

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

input:

7

output:

80

result:

ok 1 number(s): "80"

Test #5:

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

input:

8

output:

200

result:

ok 1 number(s): "200"

Test #6:

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

input:

9

output:

407

result:

ok 1 number(s): "407"

Test #7:

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

input:

10

output:

937

result:

ok 1 number(s): "937"

Test #8:

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

input:

79

output:

3224298

result:

ok 1 number(s): "3224298"

Test #9:

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

input:

123

output:

21077222

result:

ok 1 number(s): "21077222"

Test #10:

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

input:

158

output:

57411585

result:

ok 1 number(s): "57411585"

Test #11:

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

input:

285

output:

605750829

result:

ok 1 number(s): "605750829"

Test #12:

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

input:

355

output:

509863120

result:

ok 1 number(s): "509863120"

Test #13:

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

input:

484

output:

311440260

result:

ok 1 number(s): "311440260"

Test #14:

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

input:

520

output:

102191845

result:

ok 1 number(s): "102191845"

Test #15:

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

input:

706

output:

300787918

result:

ok 1 number(s): "300787918"

Test #16:

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

input:

747

output:

505062591

result:

ok 1 number(s): "505062591"

Test #17:

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

input:

784

output:

181810798

result:

ok 1 number(s): "181810798"

Test #18:

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

input:

76879

output:

716166793

result:

ok 1 number(s): "716166793"

Test #19:

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

input:

209295

output:

753032272

result:

ok 1 number(s): "753032272"

Test #20:

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

input:

220895

output:

874612082

result:

ok 1 number(s): "874612082"

Test #21:

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

input:

243390

output:

68635874

result:

ok 1 number(s): "68635874"

Test #22:

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

input:

414767

output:

862578797

result:

ok 1 number(s): "862578797"

Test #23:

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

input:

431662

output:

231728766

result:

ok 1 number(s): "231728766"

Test #24:

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

input:

521130

output:

106207351

result:

ok 1 number(s): "106207351"

Test #25:

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

input:

668419

output:

580625063

result:

ok 1 number(s): "580625063"

Test #26:

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

input:

700378

output:

790849562

result:

ok 1 number(s): "790849562"

Test #27:

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

input:

965876

output:

856082142

result:

ok 1 number(s): "856082142"

Test #28:

score: 0
Accepted
time: 60ms
memory: 42104kb

input:

998244350

output:

539142456

result:

ok 1 number(s): "539142456"

Test #29:

score: 0
Accepted
time: 56ms
memory: 40656kb

input:

998244351

output:

730264865

result:

ok 1 number(s): "730264865"

Test #30:

score: 0
Accepted
time: 53ms
memory: 40528kb

input:

998244352

output:

326703895

result:

ok 1 number(s): "326703895"

Test #31:

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

input:

998244353

output:

326703895

result:

ok 1 number(s): "326703895"

Test #32:

score: 0
Accepted
time: 60ms
memory: 40580kb

input:

998244354

output:

730264864

result:

ok 1 number(s): "730264864"

Test #33:

score: 0
Accepted
time: 54ms
memory: 42588kb

input:

998244355

output:

539142451

result:

ok 1 number(s): "539142451"

Test #34:

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

input:

998244356

output:

751581014

result:

ok 1 number(s): "751581014"

Test #35:

score: 0
Accepted
time: 104ms
memory: 47024kb

input:

2165916141

output:

216013547

result:

ok 1 number(s): "216013547"

Test #36:

score: 0
Accepted
time: 137ms
memory: 47964kb

input:

3550627266

output:

318019384

result:

ok 1 number(s): "318019384"

Test #37:

score: 0
Accepted
time: 352ms
memory: 55112kb

input:

11640239920

output:

137498099

result:

ok 1 number(s): "137498099"

Test #38:

score: 0
Accepted
time: 455ms
memory: 68992kb

input:

16191777349

output:

991399721

result:

ok 1 number(s): "991399721"

Test #39:

score: 0
Accepted
time: 716ms
memory: 74000kb

input:

31326230483

output:

99981147

result:

ok 1 number(s): "99981147"

Test #40:

score: 0
Accepted
time: 750ms
memory: 81152kb

input:

32810385543

output:

284259680

result:

ok 1 number(s): "284259680"

Test #41:

score: 0
Accepted
time: 814ms
memory: 83916kb

input:

37368395332

output:

511468046

result:

ok 1 number(s): "511468046"

Test #42:

score: 0
Accepted
time: 856ms
memory: 78108kb

input:

40002331093

output:

282851705

result:

ok 1 number(s): "282851705"

Test #43:

score: 0
Accepted
time: 1445ms
memory: 91932kb

input:

82884464396

output:

767050832

result:

ok 1 number(s): "767050832"

Test #44:

score: 0
Accepted
time: 1622ms
memory: 96364kb

input:

96506992785

output:

31413975

result:

ok 1 number(s): "31413975"

Test #45:

score: 0
Accepted
time: 1653ms
memory: 101268kb

input:

99999999995

output:

456189842

result:

ok 1 number(s): "456189842"

Test #46:

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

input:

99999999996

output:

516138273

result:

ok 1 number(s): "516138273"

Test #47:

score: 0
Accepted
time: 1677ms
memory: 104588kb

input:

99999999997

output:

136420410

result:

ok 1 number(s): "136420410"

Test #48:

score: 0
Accepted
time: 1649ms
memory: 103440kb

input:

99999999998

output:

841974696

result:

ok 1 number(s): "841974696"

Test #49:

score: 0
Accepted
time: 1667ms
memory: 103400kb

input:

99999999999

output:

164762165

result:

ok 1 number(s): "164762165"

Test #50:

score: 0
Accepted
time: 1651ms
memory: 100652kb

input:

100000000000

output:

627965619

result:

ok 1 number(s): "627965619"