QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#640899#5. 在线 O(1) 逆元masterhuang100 ✓5506ms7984kbC++20349b2024-10-14 16:48:522024-11-05 22:05:48

Judging History

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

  • [2024-11-05 22:05:48]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:5506ms
  • 内存:7984kb
  • [2024-10-14 16:48:53]
  • 评测
  • 测评结果:100
  • 用时:5197ms
  • 内存:8028kb
  • [2024-10-14 16:48:52]
  • 提交

answer

#include "inv.h"
#include<bits/stdc++.h>
using namespace std;
const int N=1<<20|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;
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 11ms
memory: 7824kb

Test #2:

score: 20
Accepted
time: 554ms
memory: 7960kb

Test #3:

score: 30
Accepted
time: 2748ms
memory: 7764kb

Test #4:

score: 20
Accepted
time: 4390ms
memory: 7844kb

Test #5:

score: 20
Accepted
time: 5506ms
memory: 7984kb