QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#620176#9309. Graphsz051WA 361ms12852kbC++201.7kb2024-10-07 16:53:122024-10-07 16:53:35

Judging History

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

  • [2024-10-07 16:53:35]
  • 评测
  • 测评结果:WA
  • 用时:361ms
  • 内存:12852kb
  • [2024-10-07 16:53:12]
  • 提交

answer

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <bitset>
#include <queue>
#define int long long
using namespace std;

const int md=998244353,B=1000000;
void read(int &x){
	x=0;
	int f=1;
	char c=getchar();
	while(!('0'<=c && c<='9')){
		if(c=='-'){
			f=-1;
		}
		c=getchar();
	}
	while('0'<=c && c<='9'){
		x=(x<<3)+(x<<1)+(c^48);
		c=getchar();
	}
	x*=f;
}
int powr(int b,int k){
	int res=1;
	for(;k;k>>=1,b=b*b%md){
		if(k&1){
			res=res*b%md;
		}
	}
	return res;
}
int ps[100010],cnt=0;
bool isp[1000010];
void sieve(int n){
	memset(isp,1,sizeof(isp));
	isp[0]=isp[1]=0;
	for(int i=2;i<=n;i++){
		if(isp[i]){
			ps[++cnt]=i;
		}
		for(int j=1;j<=cnt && ps[j]*i<=n;j++){
			isp[ps[j]*i]=0;
			if(i%ps[j]==0){
				break;
			}
		}
	}
}
int n,sum1[1000010],sum2[1000010];
int getres(int k){
	if(n/k<=2){
		return 1;
	}else if(n/k==3){
		return 3;
	}else{
		int cur=(n/k<=B?sum1[n/k]:sum2[k])-(n/(2*k)<=B?sum1[n/(2*k)]:sum2[2*k]);
		return powr(n/k,cur)*(n/k-cur-1)%md; 
	}
}
signed main(){
	sieve(1000000);
	read(n);
	for(int i=1;i<=min(B,n);i++){
		sum1[i]=i-1;
	}
	for(int i=1;i<=B;i++){
		if(n/i<=B){
			break;
		}
		sum2[i]=n/i-1;
	}
	for(int j=1;j<=cnt;j++){
		int p=ps[j];
		if(p*p>n){
			break;
		}
		for(int i=1;i<=B;i++){
			if(n/i<=B){
				break;
			}
			int v=n/i;
			if(p*p>v){
				break;
			}
			sum2[i]-=(v/p<=B?sum1[v/p]:sum2[i*p])-j+1;
		}
		for(int i=B;i;i--){
			if(p*p>i){
				break;
			}
			sum1[i]-=sum1[i/p]-j+1;
		}
	}
	int res=1;
	for(int l=1,r;l<=n;l=r+1){
		r=n/(n/l);
		res=res*powr(getres(l),r-l+1)%md;
	}
	printf("%lld",res);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 5ms
memory: 11844kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 2ms
memory: 7080kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 14ms
memory: 11008kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 24ms
memory: 11752kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 67ms
memory: 12844kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 180ms
memory: 11792kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 213ms
memory: 12852kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 342ms
memory: 11504kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 343ms
memory: 12012kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 348ms
memory: 12680kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 348ms
memory: 12508kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 349ms
memory: 11068kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 348ms
memory: 11792kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 352ms
memory: 11056kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: -100
Wrong Answer
time: 361ms
memory: 12052kb

input:

5120103302

output:

406301251

result:

wrong answer expected '116870489', found '406301251'