QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#604710#8761. 另一个计数问题UESTC_OldEastWest#WA 2ms12200kbC++171.6kb2024-10-02 13:24:582024-10-02 13:24:59

Judging History

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

  • [2024-10-02 13:24:59]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:12200kb
  • [2024-10-02 13:24:58]
  • 提交

answer

#include<cstdio>
#include<cmath>
#define ll long long
#define maxn 1000005
using namespace std;

const int M=1000000;
const ll mod=998244353,inv2=499122177,inv6=166374059;
ll n,m;
ll tot,prime[maxn],mark[maxn];
ll cnt,id1[maxn],id2[maxn];//将区间映射到连续的数组
ll g[maxn],v[maxn],sum[maxn];

void ready(ll m)
{
	for(int i=2;i<=m;++i)
	{
		if(!mark[i])
		{
			prime[++tot]=i;
			sum[tot]=(sum[tot-1]+i)%mod;
		}
		for(int j=1;j<=tot;++j)
		{
			ll x=i*prime[j];
			if(x>M)
			break;
			mark[x]=1;
			if(i%prime[j]==0)
			break;
		}
	}
}

ll getnum(ll n,ll x)
{
	return (x<=m)?id1[x]:id2[n/x];
}

ll f(ll x)//求f(x)
{
	if(x==1)
	return 0;
	else return x;
}

ll sumf(ll x)//求f(2)+...+f(x)的和
{
	ll ret=(x+2)%mod*(x-1)%mod*inv2%mod;
	return ret;
}

void pre_solve(ll n)//预处理g数组
{
	for(ll l=1,r;l<=n;l=r+1)
	{
		r=n/(n/l);
		ll val=n/l;
		if(val<=m)
		id1[val]=++cnt;
		else id2[n/val]=++cnt;
		v[cnt]=val;
		g[cnt]=sumf(val);
	}
	for(ll j=1;j<=tot;++j)
	{
		ll x=prime[j];
		for(ll i=1;i<=cnt&&x*x<=v[i];++i)
		{
			g[i]=(g[i]-f(x)*(g[getnum(n,v[i]/x)]-sum[j-1])%mod)%mod;
			g[i]=(g[i]+mod)%mod;
		}
	}
}

ll getans(ll n)
{
	m=sqrt(n);
	ready(m);
	pre_solve(n);
	return g[getnum(n,n)];
}

int main()
{
	scanf("%lld",&n);
	ll tot=(n+2)%mod*(n-1)%mod*inv2%mod;
	ll tot2=n%mod*(n+1)%mod*(2*n+1)%mod*inv6%mod;
	tot2=(tot2+mod-1)%mod;
	ll totp=getans(n)-getans(n>>1);
	ll ans=(tot*tot%mod-tot2-totp*(tot-totp)%mod*2%mod)%mod;
	ans=(ans+mod)%mod;
	ans=ans*inv2%mod;
	printf("%lld",ans);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 12184kb

input:

4

output:

8

result:

ok 1 number(s): "8"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 12200kb

input:

5

output:

23

result:

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