QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#188481#5. 在线 O(1) 逆元EnofTaiPeople100 ✓5998ms394232kbC++14403b2023-09-25 21:20:512023-09-25 21:20:51

Judging History

你现在查看的是测评时间为 2023-09-25 21:20:51 的历史记录

  • [2024-11-05 21:52:24]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:5454ms
  • 内存:394516kb
  • [2023-09-25 21:20:51]
  • 评测
  • 测评结果:100
  • 用时:5998ms
  • 内存:394232kb
  • [2023-09-25 21:20:51]
  • 提交

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){
	return sol(x);
}

详细

Test #1:

score: 30
Accepted
time: 746ms
memory: 394228kb

Test #2:

score: 40
Accepted
time: 1238ms
memory: 394232kb

Test #3:

score: 30
Accepted
time: 5998ms
memory: 394212kb