QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#640907#5. 在线 O(1) 逆元masterhuang100 ✓4706ms19080kbC++20348b2024-10-14 16:50:402024-10-14 16:50:41

Judging History

This is a historical verdict posted at 2024-10-14 16:50:41.

  • [2024-11-05 22:06:12]
  • 管理员手动重测本题所有提交记录
  • Verdict: 100
  • Time: 5117ms
  • Memory: 19112kb
  • [2024-10-14 16:50:41]
  • Judged
  • Verdict: 100
  • Time: 4706ms
  • Memory: 19080kb
  • [2024-10-14 16:50:40]
  • Submitted

answer

#include "inv.h"
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353,N=mod>>8;
int n=N-1,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: 30
Accepted
time: 23ms
memory: 19076kb

Test #2:

score: 40
Accepted
time: 472ms
memory: 18908kb

Test #3:

score: 30
Accepted
time: 4706ms
memory: 19080kb