QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#650587#5. 在线 O(1) 逆元yduck100 ✓5615ms394508kbC++14358b2024-10-18 15:41:562024-11-05 22:06:34

Judging History

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

  • [2024-11-05 22:06:34]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:5615ms
  • 内存:394508kb
  • [2024-10-18 15:41:57]
  • 评测
  • 测评结果:100
  • 用时:5150ms
  • 内存:394496kb
  • [2024-10-18 15:41:56]
  • 提交

answer

#include "inv.h"

const int N = 1e8;
int mod;
int inv_list[N + 7];

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

int inv(int x){
	if (x <= N) return inv_list[x];
	return mod - 1ll * (mod / x) * inv(mod % x) % mod;
}

详细


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 818ms
memory: 394508kb

Test #2:

score: 20
Accepted
time: 1261ms
memory: 394476kb

Test #3:

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

Test #4:

score: 20
Accepted
time: 4654ms
memory: 394508kb

Test #5:

score: 20
Accepted
time: 5615ms
memory: 394432kb