QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136494#5. 在线 O(1) 逆元zhouhuanyi100 ✓5842ms394240kbC++14465b2023-08-08 21:18:032023-08-08 21:18:04

Judging History

This is a historical verdict posted at 2023-08-08 21:18:04.

  • [2024-11-05 21:51:30]
  • 管理员手动重测本题所有提交记录
  • Verdict: 100
  • Time: 5210ms
  • Memory: 394352kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-08 21:18:04]
  • Judged
  • Verdict: 100
  • Time: 5842ms
  • Memory: 394240kb
  • [2023-08-08 21:18:03]
  • Submitted

answer

#include<iostream>
#include<cstdio>
#define mod 998244353
#define N 100000000
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<=N;++i) invs[i]=MD2(-1ll*(mod/i)*invs[mod%i]%mod);
	return;
}
int inv(int x)
{
	int a,b;
	if (x<=N) 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

Test #1:

score: 30
Accepted
time: 749ms
memory: 394240kb

Test #2:

score: 40
Accepted
time: 1273ms
memory: 394224kb

Test #3:

score: 30
Accepted
time: 5842ms
memory: 394156kb