QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#252450#7710. Rikka with EquationSolitaryDream#AC ✓282ms321220kbC++171.6kb2023-11-15 19:42:552023-11-15 19:42:55

Judging History

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

  • [2023-11-15 19:42:55]
  • 评测
  • 测评结果:AC
  • 用时:282ms
  • 内存:321220kb
  • [2023-11-15 19:42:55]
  • 提交

answer

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

#define int long long

const int N=1e7+1e3+7,P=998244353;

int T,n;

int ans[N],vis[N],p[N],ptot,cnt[N],fr[N];

int f(int p,int k)
{
    if(p==2)
    {
        if(k==1)
            return 3;
        if(k==2)
            return 5;
        if(k==3)
            return 11;
        int ret=29,dlt=25;
        for(int t=4;t<k;t++)
        {
            ret=(ret*4-dlt+P)%P;
            if(t%2==1)
                dlt=(dlt+10)%P;
            else
                dlt=(dlt*4-53+P)%P;
        }
        // cerr<<dlt<<" ";
        return ret;
    }
    else
    {
        int ret=1;
        for(int t=1;t<=k;t++)
            ret=(ret*p%P-(t%2==0?p-1:(p-1)/2)+P)%P;
        return ret*ret%P;
    }
}

void pre(int n)
{
    ans[1]=1;
    for(int i=2;i<=n;i++)
    {
        if(!vis[i])
            p[++ptot]=i,ans[i]=f(i,1),cnt[i]=1,fr[i]=1;
        for(int j=1;j<=ptot&&i*p[j]<=n;j++)
        {
            vis[i*p[j]]=1;
            ans[i*p[j]]=ans[i]*ans[p[j]]%P;
            if(i%p[j])
                cnt[i*p[j]]=1,fr[i*p[j]]=i;
            if(i%p[j]==0)
            {
                cnt[i*p[j]]=cnt[i]+1;
                fr[i*p[j]]=fr[i];
                ans[i*p[j]]=f(p[j],cnt[i*p[j]])*ans[fr[i*p[j]]]%P;
                break;
            }
        }
    }
    // for(int i=1;i<=50;i++)
    //     cout<<ans[i]<<"\n";
    for(int i=1;i<=n;i++)
        ans[i]=(ans[i]+ans[i-1])%P;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    pre(1e7);
    cin>>T;
    while(T--)
    {
        cin>>n;
        cout<<ans[n]<<"\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 243ms
memory: 321220kb

input:

5
3
5
10
100
1000

output:

8
22
104
45933
32791150

result:

ok 5 number(s): "8 22 104 45933 32791150"

Test #2:

score: 0
Accepted
time: 282ms
memory: 321116kb

input:

100000
8045782
8876486
8163011
8344042
9378740
2908104
7853239
1557591
6565197
5962616
7951650
7994086
4609270
5375583
3214533
3208595
7727951
4566166
6848279
9075146
3592143
4991697
3179065
7683833
4880753
6492999
8016415
6388967
1319335
269048
1712061
5888121
3847377
7435670
1768073
655758
6372575...

output:

566372506
613340079
457470593
909412476
204288085
145326690
470913242
580308507
451513374
742372505
578473430
164558269
901594473
47845389
44481127
90637625
933713038
936835953
115876485
201678620
924867979
120570904
376719500
699611349
285842222
772019635
996465492
526862153
638097420
586450685
867...

result:

ok 100000 numbers