QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#241467#5. 在线 O(1) 逆元mfeitveer100 ✓5639ms511552kbC++14421b2023-11-06 08:13:212023-11-06 08:13:21

Judging History

你现在查看的是测评时间为 2023-11-06 08:13:21 的历史记录

  • [2024-11-05 21:54:57]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:5165ms
  • 内存:511692kb
  • [2023-11-06 08:13:21]
  • 评测
  • 测评结果:100
  • 用时:5639ms
  • 内存:511552kb
  • [2023-11-06 08:13:21]
  • 提交

answer

#include "inv.h"

const int N = 130000010;
const int mod = 998244353;

typedef long long ll;

int Inv[N];

ll ask(ll x) {
	ll res = 1;
	while(x > 130000000)
		res = res * (mod - mod / x) % mod, x = mod % x;
	return res * Inv[x] % mod;
}

void init(int p) {
	Inv[1] = 1;
	for(int i = 2;i <= 130000000;i++)
		Inv[i] = 1ll * (mod - mod / i) * Inv[mod % i] % mod;
}

int inv(int x) {
	return ask(x);
}

Details

Test #1:

score: 30
Accepted
time: 872ms
memory: 511392kb

Test #2:

score: 40
Accepted
time: 1375ms
memory: 511552kb

Test #3:

score: 30
Accepted
time: 5639ms
memory: 511332kb