QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#571474#9309. GraphUSTC_fish_touching_teamWA 0ms14180kbC++141.7kb2024-09-17 23:23:112024-09-17 23:23:11

Judging History

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

  • [2024-09-17 23:23:11]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:14180kb
  • [2024-09-17 23:23:11]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#define LL long long
#define FOR(i,x,y) for(int i=x;i<y;i++)
using namespace std;

namespace min25{
	const int M=2e6+100;
	LL B,N;
	
	inline LL pg(LL x){return 1;}
	inline LL psg(LL x){return x-1;}
	
	LL pr[M],pc,sg[M];
	void get_prime(LL n){
		static bool vis[M];pc=0;
		FOR(i,2,n+1){
			if(!vis[i]){
				pr[pc++]=i;
				sg[pc]=(sg[pc-1]+pg(i));
			}
			FOR(j,0,pc){
				if(pr[j]*i>n)break;
				vis[pr[j]*i]=1;
				if(i%pr[j]==0)break;
			}
		}
	}
	
	LL w[M];
	LL id1[M],id2[M],g[M];
	inline LL id(LL x){
		return x<=B?id1[x]:id2[N/x];
	}
	
	void solve(LL _N){
		N=_N;
		B=sqrt(N+5);
		get_prime(B);
		int sz=0;
		for(LL l=1,v,r;l<=N;l=r+1){
			v=N/l;r=N/v;
			w[sz]=v;g[sz]=psg(v);
			if(v<=B)id1[v]=sz;
			else id2[r]=sz;
			sz++;
		}
		
		FOR(k,0,pc){
			LL p=pr[k];
			FOR(i,0,sz){
				LL v=w[i];if(p*p>v)break;
				LL t=id(v/p);
				g[i]=(g[i]-(g[t]-sg[k])*pg(p));
			}
		}
	}
	
	LL calc(LL l,LL r){
		return g[id(r)]-g[id(l-1)];
	}
}

const LL mod=998244353;

LL Pow(LL a,LL b){
	LL r=1;a%=mod; 
	while(b){
		if(b&1)r=r*a%mod;
		b>>=1; a=a*a%mod;
	}
	return r;
}

LL solve(LL n){
	if(n==1)return 0; 
	return min25::calc(n/2+1,n);
}

LL n;
int main(){
	scanf("%lld",&n);
	
	
	min25::solve(n);
	printf("%lld\n",min25::g[min25::id(n)]);
	
	LL res=1;
	for(LL l=1,v,r;l<=n;l=r+1){
		v=n/l,r=n/v;
		if(v<=2)break;
		
		LL g=solve(v)+1;
//		printf("v=%lld g=%lld l=%lld\n",v,g,l);
//		printf("l=%lld v=%lld b=%lld\n",l,v,b);
		LL val=Pow(v,g-1)*((v-g)%mod)%mod;
		if(v==g)val=Pow(v,g-2);
		res=res*Pow(val,r-l+1)%mod;
	}
	
	printf("%lld",(res%mod+mod)%mod);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4

output:

2
8

result:

wrong answer expected '8', found '2'