QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#641018#5. 在线 O(1) 逆元SkyMaths100 ✓5557ms394508kbC++14849b2024-10-14 17:42:032024-10-14 17:42:03

Judging History

你现在查看的是测评时间为 2024-10-14 17:42:03 的历史记录

  • [2024-11-05 22:06:13]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:5286ms
  • 内存:394540kb
  • [2024-10-14 17:42:03]
  • 评测
  • 测评结果:100
  • 用时:5557ms
  • 内存:394508kb
  • [2024-10-14 17:42:03]
  • 提交

answer

#pragma GCC optimize("-Ofast", "-finline", "-funroll-loops", "-fno-stack-protector")
#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;
}

// const int inf = 1e9;
// mt19937 mtrnd(time(0));
// signed main() {
// 	init(Mod);
// 	rep (t, 1, 10) {
// 		int x = mtrnd() % inf + 1;
// 		assert(1ll * x * inv(x) % Mod == 1);
// 	}
// 	return 0;
// }

详细


Pretests


Final Tests

Test #1:

score: 30
Accepted
time: 766ms
memory: 394504kb

Test #2:

score: 40
Accepted
time: 1293ms
memory: 394508kb

Test #3:

score: 30
Accepted
time: 5557ms
memory: 394312kb