QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#641048#5. 在线 O(1) 逆元SkyMaths100 ✓4723ms394520kbC++20546b2024-10-14 18:04:292024-11-05 22:06:28

Judging History

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

  • [2024-11-05 22:06:28]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:4723ms
  • 内存:394520kb
  • [2024-10-14 18:04:34]
  • 评测
  • 测评结果:100
  • 用时:4877ms
  • 内存:394456kb
  • [2024-10-14 18:04:29]
  • 提交

answer

#include<bits/stdc++.h>
// #include "inv.h"
#define rep(i,l,r) for (int i(l), i##end(r); i <= i##end; ++i)
#define per(i,r,l) for (int i(r), i##end(l); i >= i##end; --i)
using namespace std;

const int N = 1e8 + 9, Mod = 998244353;
int n = N - 9, MMI[N];
void init(int p) {
	MMI[1] = 1;
	rep (i, 2, n) MMI[i] = Mod - 1ll * (Mod / i) * MMI[Mod % i] % Mod;
}
int inv(int x) {
	if (x <= n) return MMI[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: 10
Accepted
time: 600ms
memory: 394520kb

Test #2:

score: 20
Accepted
time: 997ms
memory: 394396kb

Test #3:

score: 30
Accepted
time: 2622ms
memory: 394320kb

Test #4:

score: 20
Accepted
time: 3902ms
memory: 394324kb

Test #5:

score: 20
Accepted
time: 4723ms
memory: 394500kb