QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#128663#5. 在线 O(1) 逆元Leasier80 4929ms42952kbC++11358b2023-07-21 14:39:462024-11-05 21:50:51

Judging History

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

  • [2024-11-05 21:50:51]
  • 管理员手动重测本题所有提交记录
  • 测评结果:80
  • 用时:4929ms
  • 内存:42952kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-21 14:39:48]
  • 评测
  • 测评结果:70
  • 用时:808ms
  • 内存:42676kb
  • [2023-07-21 14:39:46]
  • 提交

answer

#include "inv.h"

const int N = 1e7;
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;
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 61ms
memory: 42920kb

Test #2:

score: 20
Accepted
time: 661ms
memory: 42844kb

Test #3:

score: 30
Accepted
time: 3105ms
memory: 42952kb

Test #4:

score: 20
Accepted
time: 4929ms
memory: 42944kb

Test #5:

score: 0
Time Limit Exceeded