QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#604675#8761. 另一个计数问题lllei#WA 0ms8728kbC++202.8kb2024-10-02 13:01:412024-10-02 13:01:41

Judging History

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

  • [2024-10-02 13:01:41]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:8728kb
  • [2024-10-02 13:01:41]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
using LL = 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);
                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);
    //freopen("test2.out","w",stdout);
    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)%mod;
    ans%=mod;
    ans=(ans+mod)%mod;
    cout<<ans<<'\n';
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 8728kb

input:

4

output:

1

result:

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