QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136495#5. 在线 O(1) 逆元yyyyxh100 ✓5541ms81964kbC++17430b2023-08-08 21:21:442023-08-08 21:21:47

Judging History

你现在查看的是测评时间为 2023-08-08 21:21:47 的历史记录

  • [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;
}

詳細信息

Test #1:

score: 30
Accepted
time: 190ms
memory: 81768kb

Test #2:

score: 40
Accepted
time: 704ms
memory: 81708kb

Test #3:

score: 30
Accepted
time: 5541ms
memory: 81964kb