QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#241464#5. 在线 O(1) 逆元mfeitveer100 ✓5645ms394536kbC++14382b2023-11-06 08:05:442024-11-05 21:54:46

Judging History

This is the latest submission verdict.

  • [2024-11-05 21:54:46]
  • 管理员手动重测本题所有提交记录
  • Verdict: 100
  • Time: 5645ms
  • Memory: 394536kb
  • [2023-11-06 08:05:45]
  • Judged
  • Verdict: 100
  • Time: 5967ms
  • Memory: 394388kb
  • [2023-11-06 08:05:44]
  • Submitted

answer

#include "inv.h"

const int N = 100000010;
const int mod = 998244353;

typedef long long ll;

int Inv[N];

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

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

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

詳細信息


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 932ms
memory: 394520kb

Test #2:

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

Test #3:

score: 30
Accepted
time: 4220ms
memory: 394536kb

Test #4:

score: 20
Accepted
time: 5207ms
memory: 394384kb

Test #5:

score: 20
Accepted
time: 5645ms
memory: 394520kb