QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#780394#5. 在线 O(1) 逆元GoatGirl98100 ✓4635ms42964kbC++14301b2024-11-25 10:39:442024-11-25 10:39:50

Judging History

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

  • [2024-11-25 10:39:50]
  • 评测
  • 测评结果:100
  • 用时:4635ms
  • 内存:42964kb
  • [2024-11-25 10:39:44]
  • 提交

answer

#include "inv.h"
const int N=1e7+5,mod=998244353;
int n=N-5, I[N];
void init(int p)
{
	I[1]=1;
	for(int i=2;i<=n;i++) I[i]=mod-1ll*(mod/i)*I[mod%i]%mod;
}
int inv(int x)
{
	if(x<=n) return I[x];int q=mod/x,r=mod%x;
	if(r<x/2) return mod-1ll*q*inv(r)%mod;
	return 1ll*(q+1)*inv(x-r)%mod;
}

詳細信息


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 46ms
memory: 42768kb

Test #2:

score: 20
Accepted
time: 517ms
memory: 42964kb

Test #3:

score: 30
Accepted
time: 2358ms
memory: 42944kb

Test #4:

score: 20
Accepted
time: 3744ms
memory: 42948kb

Test #5:

score: 20
Accepted
time: 4635ms
memory: 42828kb