QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#604682#8761. 另一个计数问题lllei#AC ✓924ms39852kbC++202.8kb2024-10-02 13:07:432024-10-02 13:07:44

Judging History

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

  • [2024-10-02 13:07:44]
  • 评测
  • 测评结果:AC
  • 用时:924ms
  • 内存:39852kb
  • [2024-10-02 13:07:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long 
const int mod=998244353,inv2=(mod+1)/2,inv3=(mod+1)/3;
namespace Min_25
{
    
    const int maxn=1e6+10;
    int md(int x){return x>=mod?x-mod:x;}
    bool flag[maxn];
    int g1[maxn],g2[maxn];
    long long w[maxn];
    int id1[maxn],id2[maxn],m;
    int sum1[maxn],sum2[maxn],lim;
    int prime[maxn],cnt=0;
    void make_prime(int n)
    {
        for(int i=2;i<=n;i++)
        {
            if(!flag[i])
            {
                prime[++cnt]=i;
                sum1[cnt]=(sum1[cnt-1]+i)%mod;
                sum2[cnt]=(sum2[cnt-1]+i*1LL*i)%mod;
            }
            for(int j=1;j<=cnt&&prime[j]*i<=n;j++)
            {
                flag[prime[j]*i]=1;
                if(i%prime[j]==0)break;
            }
        }
    }
    long long n;
    void G()
    {
        m=0;
        for(long long i=1,j;i<=n;i=j+1)
        {
            w[++m]=n/i,j=n/w[m];
            if(w[m]<=lim)id1[w[m]]=m;
            else id2[n/w[m]]=m;
            int t=w[m]%mod;
            g1[m]=(t+1)*1LL*t/2%mod-1;
            g2[m]=(t+1)*1LL*t/2%mod*(t*2+1)%mod*inv3%mod-1;
        }
        for(int i=1;i<=cnt;i++)
        for(int j=1;j<=m&&prime[i]*1LL*prime[i]<=w[j];j++)
        {
            int lst=w[j]/prime[i]<=lim?id1[w[j]/prime[i]]:id2[n/(w[j]/prime[i])];
            g1[j]=md(g1[j]+mod-(g1[lst]-sum1[i-1]+mod)*1LL*prime[i]%mod);
            g2[j]=md(g2[j]+mod-(g2[lst]-sum2[i-1]+mod)*1LL*prime[i]%mod*prime[i]%mod);
        }
    }
    pair<int,int> Sum(long long N)
    {
        memset(flag,0,sizeof(flag));
        m=0,cnt=0;
        n=N;
        lim=sqrt(n);
        make_prime(lim);
        G();
        //memset(flag,0,sizeof(flag));
       // cnt=0; 
       // make_prime(N);
        //cout<<sum1[cnt]<<" "<<sum2[cnt]<<endl;
        //cout<<g1[1]<<" "<<g2[1]<<endl;
        return make_pair(g1[1],g2[1]);
    }
}
int Pow(int a,long long k)
{
    int ret=1;
    while(k)
    {
        if(k&1)ret=ret*1LL*a%mod;
        a=a*1LL*a%mod;
        k>>=1;
    }
    return ret;
}
int sum2(long long x)
{
    x%=mod;
    return x*(x+1)%mod*(2*x+1)%mod*Pow(6,mod-2)%mod;
}
int sum1(long long x)
{
    x%=mod;
    return x*(x+1)%mod*inv2%mod;
}
long long n;
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    auto t1=Min_25::Sum(n);
    auto t2=Min_25::Sum(n/2);
    long long ans=(sum1(n)*1LL*sum1(n)%mod+mod-sum2(n))%mod*inv2%mod;
    ans-=sum1(n)-1;
    ans%=mod;
    ans-=(t1.first-t2.first)*1LL*sum1(n)%mod;
    //cout<<ans<<endl;
    ans+=((t1.second-t2.second)+(t1.first-t2.first)*1LL*(t1.first-t2.first)%mod)%mod*inv2%mod;
    ans+=(t1.first-t2.first);
    ans%=mod;
    ans=(ans+mod)%mod;
    cout<<ans<<'\n';
    return 0;
}

详细

Test #1:

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

input:

4

output:

8

result:

ok 1 number(s): "8"

Test #2:

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

input:

5

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

input:

6

output:

80

result:

ok 1 number(s): "80"

Test #4:

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

input:

7

output:

80

result:

ok 1 number(s): "80"

Test #5:

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

input:

8

output:

200

result:

ok 1 number(s): "200"

Test #6:

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

input:

9

output:

407

result:

ok 1 number(s): "407"

Test #7:

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

input:

10

output:

937

result:

ok 1 number(s): "937"

Test #8:

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

input:

79

output:

3224298

result:

ok 1 number(s): "3224298"

Test #9:

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

input:

123

output:

21077222

result:

ok 1 number(s): "21077222"

Test #10:

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

input:

158

output:

57411585

result:

ok 1 number(s): "57411585"

Test #11:

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

input:

285

output:

605750829

result:

ok 1 number(s): "605750829"

Test #12:

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

input:

355

output:

509863120

result:

ok 1 number(s): "509863120"

Test #13:

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

input:

484

output:

311440260

result:

ok 1 number(s): "311440260"

Test #14:

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

input:

520

output:

102191845

result:

ok 1 number(s): "102191845"

Test #15:

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

input:

706

output:

300787918

result:

ok 1 number(s): "300787918"

Test #16:

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

input:

747

output:

505062591

result:

ok 1 number(s): "505062591"

Test #17:

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

input:

784

output:

181810798

result:

ok 1 number(s): "181810798"

Test #18:

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

input:

76879

output:

716166793

result:

ok 1 number(s): "716166793"

Test #19:

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

input:

209295

output:

753032272

result:

ok 1 number(s): "753032272"

Test #20:

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

input:

220895

output:

874612082

result:

ok 1 number(s): "874612082"

Test #21:

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

input:

243390

output:

68635874

result:

ok 1 number(s): "68635874"

Test #22:

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

input:

414767

output:

862578797

result:

ok 1 number(s): "862578797"

Test #23:

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

input:

431662

output:

231728766

result:

ok 1 number(s): "231728766"

Test #24:

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

input:

521130

output:

106207351

result:

ok 1 number(s): "106207351"

Test #25:

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

input:

668419

output:

580625063

result:

ok 1 number(s): "580625063"

Test #26:

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

input:

700378

output:

790849562

result:

ok 1 number(s): "790849562"

Test #27:

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

input:

965876

output:

856082142

result:

ok 1 number(s): "856082142"

Test #28:

score: 0
Accepted
time: 34ms
memory: 21000kb

input:

998244350

output:

539142456

result:

ok 1 number(s): "539142456"

Test #29:

score: 0
Accepted
time: 38ms
memory: 21096kb

input:

998244351

output:

730264865

result:

ok 1 number(s): "730264865"

Test #30:

score: 0
Accepted
time: 34ms
memory: 18888kb

input:

998244352

output:

326703895

result:

ok 1 number(s): "326703895"

Test #31:

score: 0
Accepted
time: 38ms
memory: 20168kb

input:

998244353

output:

326703895

result:

ok 1 number(s): "326703895"

Test #32:

score: 0
Accepted
time: 37ms
memory: 20316kb

input:

998244354

output:

730264864

result:

ok 1 number(s): "730264864"

Test #33:

score: 0
Accepted
time: 34ms
memory: 20800kb

input:

998244355

output:

539142451

result:

ok 1 number(s): "539142451"

Test #34:

score: 0
Accepted
time: 35ms
memory: 18652kb

input:

998244356

output:

751581014

result:

ok 1 number(s): "751581014"

Test #35:

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

input:

2165916141

output:

216013547

result:

ok 1 number(s): "216013547"

Test #36:

score: 0
Accepted
time: 86ms
memory: 23136kb

input:

3550627266

output:

318019384

result:

ok 1 number(s): "318019384"

Test #37:

score: 0
Accepted
time: 204ms
memory: 23208kb

input:

11640239920

output:

137498099

result:

ok 1 number(s): "137498099"

Test #38:

score: 0
Accepted
time: 257ms
memory: 25296kb

input:

16191777349

output:

991399721

result:

ok 1 number(s): "991399721"

Test #39:

score: 0
Accepted
time: 404ms
memory: 29408kb

input:

31326230483

output:

99981147

result:

ok 1 number(s): "99981147"

Test #40:

score: 0
Accepted
time: 416ms
memory: 29228kb

input:

32810385543

output:

284259680

result:

ok 1 number(s): "284259680"

Test #41:

score: 0
Accepted
time: 453ms
memory: 27456kb

input:

37368395332

output:

511468046

result:

ok 1 number(s): "511468046"

Test #42:

score: 0
Accepted
time: 476ms
memory: 32852kb

input:

40002331093

output:

282851705

result:

ok 1 number(s): "282851705"

Test #43:

score: 0
Accepted
time: 820ms
memory: 35512kb

input:

82884464396

output:

767050832

result:

ok 1 number(s): "767050832"

Test #44:

score: 0
Accepted
time: 894ms
memory: 37752kb

input:

96506992785

output:

31413975

result:

ok 1 number(s): "31413975"

Test #45:

score: 0
Accepted
time: 924ms
memory: 39452kb

input:

99999999995

output:

456189842

result:

ok 1 number(s): "456189842"

Test #46:

score: 0
Accepted
time: 922ms
memory: 37900kb

input:

99999999996

output:

516138273

result:

ok 1 number(s): "516138273"

Test #47:

score: 0
Accepted
time: 915ms
memory: 37688kb

input:

99999999997

output:

136420410

result:

ok 1 number(s): "136420410"

Test #48:

score: 0
Accepted
time: 911ms
memory: 37812kb

input:

99999999998

output:

841974696

result:

ok 1 number(s): "841974696"

Test #49:

score: 0
Accepted
time: 908ms
memory: 39852kb

input:

99999999999

output:

164762165

result:

ok 1 number(s): "164762165"

Test #50:

score: 0
Accepted
time: 911ms
memory: 37808kb

input:

100000000000

output:

627965619

result:

ok 1 number(s): "627965619"