QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#298946#5. 在线 O(1) 逆元Untitled_unrevised60 5044ms490772kbC++14395b2024-01-06 16:06:552024-11-05 21:57:27

Judging History

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

  • [2024-11-05 21:57:27]
  • 管理员手动重测本题所有提交记录
  • 测评结果:60
  • 用时:5044ms
  • 内存:490772kb
  • [2024-01-06 16:06:55]
  • 评测
  • 测评结果:70
  • 用时:1495ms
  • 内存:490600kb
  • [2024-01-06 16:06:55]
  • 提交

answer

#include <vector>
#include "inv.h"

std::vector<int> invmem;
unsigned long long s;
int P;

void init(int p) {
	s = ((p - 1) >> 3) + 1;
	invmem = std::vector<int>(s);
	P = p;
	invmem[1] = 1;
}

int inv(int x) {
	if(x >= s) return P - (unsigned long long) (P / x) * inv(P % x) % P;
	return invmem[x] ? invmem[x] : (invmem[x] = P - (unsigned long long) (P / x) * inv(P % x) % P);
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 24ms
memory: 490744kb

Test #2:

score: 20
Accepted
time: 1262ms
memory: 490764kb

Test #3:

score: 30
Accepted
time: 5044ms
memory: 490772kb

Test #4:

score: 0
Time Limit Exceeded

Test #5:

score: 0
Time Limit Exceeded