QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#641050#5. 在线 O(1) 逆元SkyMaths100 ✓5003ms394536kbC++20347b2024-10-14 18:05:152024-10-14 18:05:15

Judging History

你现在查看的是测评时间为 2024-10-14 18:05:15 的历史记录

  • [2024-11-05 22:06:29]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:4816ms
  • 内存:394448kb
  • [2024-10-14 18:05:15]
  • 评测
  • 测评结果:100
  • 用时:5003ms
  • 内存:394536kb
  • [2024-10-14 18:05:15]
  • 提交

answer

#include "inv.h"
#include<bits/stdc++.h>
using namespace std;
const int N=1e8+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: 30
Accepted
time: 651ms
memory: 394532kb

Test #2:

score: 40
Accepted
time: 1099ms
memory: 394536kb

Test #3:

score: 30
Accepted
time: 5003ms
memory: 394352kb