QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#241462#5. 在线 O(1) 逆元mfeitveer80 5461ms394516kbC++14372b2023-11-06 08:03:272024-11-05 21:54:32

Judging History

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

  • [2024-11-05 21:54:32]
  • 管理员手动重测本题所有提交记录
  • 测评结果:80
  • 用时:5461ms
  • 内存:394516kb
  • [2023-11-06 08:03:27]
  • 评测
  • 测评结果:70
  • 用时:1221ms
  • 内存:394212kb
  • [2023-11-06 08:03:27]
  • 提交

answer

#include "inv.h"

const int N = 50000010;
const int mod = 998244353;

typedef long long ll;

ll Inv[N];

ll ask(ll x) {
    return (x <= 50000000 ? Inv[x] : (mod - mod / x) * ask(mod % x) % mod);
}

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

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

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 592ms
memory: 394448kb

Test #2:

score: 20
Accepted
time: 1168ms
memory: 394408kb

Test #3:

score: 30
Accepted
time: 3606ms
memory: 394516kb

Test #4:

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

Test #5:

score: 0
Time Limit Exceeded