QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#579139#9309. GraphBob_WangWA 0ms12200kbC++171.6kb2024-09-21 09:35:532024-09-21 09:35:53

Judging History

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

  • [2024-09-21 09:35:53]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:12200kb
  • [2024-09-21 09:35:53]
  • 提交

answer

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

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

ll mul(ll x,ll y)
{
	if(y<0)
	return 1;
	x%=mod;
	ll ret=1;
	while(y)
	{
		if(y&1)
		ret=ret*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return ret;
}

void ready(ll m)
{
	for(int i=2;i<=m;++i)
	{
		if(!mark[i])
		prime[++tot]=i;
		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 1;
}

ll sumf(ll x)//求f(2)+...+f(x)的和
{
	return x-1;
}

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[getnum(n,v[i]/x)]-(j-1);
	}
}

ll getprime(ll n)
{
	tot=cnt=0;
	m=sqrt(n);
	ready(m);
	pre_solve(n);
	return g[getnum(n,n)];
}

int main()
{
	scanf("%lld",&n);
	ll ans=1;
	for(ll l=1,r;l<=n;l=r+1)
	{
		r=n/(n/l);
		ll cnt=n/l,tot_p=(getprime(cnt)-getprime(cnt>>1))%mod;
		ll del;
		if((cnt>>1)>=2)
		del=(cnt-tot_p-1)%mod*mul(tot_p+2,tot_p)%mod;
		else del=mul(tot_p+1,tot_p-1)%mod;
		ans=ans*mul(del,r-l+1)%mod;
	}
	printf("%lld",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4

output:

6

result:

wrong answer expected '8', found '6'