QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#188483#5. 在线 O(1) 逆元EnofTaiPeople100 ✓5347ms394464kbC++14533b2023-09-25 21:23:282024-11-05 21:52:26

Judging History

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

  • [2024-11-05 21:52:26]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:5347ms
  • 内存:394464kb
  • [2023-09-25 21:23:29]
  • 评测
  • 测评结果:70
  • 用时:1255ms
  • 内存:394432kb
  • [2023-09-25 21:23:28]
  • 提交

answer

#include<bits/stdc++.h>
#include "inv.h"
using namespace std;
using ll=long long;
const int N=1e8+8,M=998244353;
int nv[N];
void init(int p){
	int x;
	nv[0]=nv[1]=1;
	for(x=2;x<N;++x)
		nv[x]=ll(M-M/x)*nv[M%x]%M;
}
int sol(int d){
	if(d<N)return nv[d];
	if(d<M-d){
		return ll(M-M/d)*sol(M%d)%M;
	}else{
		d=M-d;
		return ll(M/d)*sol(M%d)%M;
	}
}
int inv(int x){
	ll res=1;
	while(x>=N){
		if(x<M-x)(res*=-M/x)%=M,x=M%x;
		else x=M-x,(res*=M/x)%=M,x=M%x;
	}
	((res*=nv[x])%=M)<0&&(res+=M);
	return res;
}

详细


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 683ms
memory: 394456kb

Test #2:

score: 20
Accepted
time: 1194ms
memory: 394400kb

Test #3:

score: 30
Accepted
time: 2981ms
memory: 394464kb

Test #4:

score: 20
Accepted
time: 4348ms
memory: 394396kb

Test #5:

score: 20
Accepted
time: 5347ms
memory: 394448kb