QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136489#5. 在线 O(1) 逆元zhouhuanyi80 5846ms4004kbC++14471b2023-08-08 20:57:352024-11-05 21:51:12

Judging History

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

  • [2024-11-05 21:51:12]
  • 管理员手动重测本题所有提交记录
  • 测评结果:80
  • 用时:5846ms
  • 内存:4004kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-08 20:57:37]
  • 评测
  • 测评结果:70
  • 用时:800ms
  • 内存:3700kb
  • [2023-08-08 20:57:35]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define mod 998244353
#define N 31595
using namespace std;
int MD2(int x)
{
	return x<0?x+mod:x;
}
int T,invs[N+1];
void init(int p)
{
	invs[1]=1;
	for (int i=2;i*i<=mod;++i) invs[i]=MD2(-1ll*(mod/i)*invs[mod%i]%mod);
	return;
}
int inv(int x)
{
	int a,b;
	if (1ll*x*x<=mod) return invs[x];
	else
	{
		a=mod/x,b=mod%x;
		if ((b<<1)<=x) return 1ll*MD2(-a)*inv(b)%mod;
		else return 1ll*(a+1)*inv(x-b)%mod;
	}
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 8ms
memory: 3996kb

Test #2:

score: 20
Accepted
time: 741ms
memory: 4004kb

Test #3:

score: 30
Accepted
time: 3654ms
memory: 3812kb

Test #4:

score: 20
Accepted
time: 5846ms
memory: 3996kb

Test #5:

score: 0
Time Limit Exceeded