QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136495#5. 在线 O(1) 逆元yyyyxh100 ✓4920ms82004kbC++17430b2023-08-08 21:21:442024-11-05 21:51:30

Judging History

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

  • [2024-11-05 21:51:30]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:4920ms
  • 内存:82004kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-08 21:21:47]
  • 评测
  • 测评结果:100
  • 用时:5541ms
  • 内存:81964kb
  • [2023-08-08 21:21:44]
  • 提交

answer

#include <cstdio>
#include <cassert>
#pragma GCC optimize(2,3,"Ofast")
using namespace std;
const int P=998244353,N=20000003;
typedef long long ll;
int a[N];
void init(int _P){
	assert(_P==P);
	a[1]=1;
	for(int i=2;i<N;++i) a[i]=(ll)a[P%i]*(P-P/i)%P;
}
int inv(int x){
	int res=1;
	while(x>=N){
		int t=P%x;
		if(x-t<t) res=(ll)res*(P/x+1)%P,x-=t;
		else res=(ll)res*(P-P/x)%P,x=t;
	}
	return (ll)res*a[x]%P;
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 152ms
memory: 82004kb

Test #2:

score: 20
Accepted
time: 616ms
memory: 82004kb

Test #3:

score: 30
Accepted
time: 2471ms
memory: 81896kb

Test #4:

score: 20
Accepted
time: 3936ms
memory: 82000kb

Test #5:

score: 20
Accepted
time: 4920ms
memory: 82000kb