QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#640902#5. 在线 O(1) 逆元masterhuang70 ✓683ms20272kbC++20349b2024-10-14 16:49:192024-10-14 16:49:24

Judging History

This is a historical verdict posted at 2024-10-14 16:49:24.

  • [2024-11-05 22:06:09]
  • 管理员手动重测本题所有提交记录
  • Verdict: 100
  • Time: 4642ms
  • Memory: 20268kb
  • [2024-10-14 16:49:24]
  • Judged
  • Verdict: 70
  • Time: 683ms
  • Memory: 20272kb
  • [2024-10-14 16:49:19]
  • Submitted

answer

#include "inv.h"
#include<bits/stdc++.h>
using namespace std;
const int N=1<<22|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: 18ms
memory: 20272kb

Test #2:

score: 40
Accepted
time: 683ms
memory: 20108kb

Test #3:

score: 0
Time Limit Exceeded