QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#298946#5. 在线 O(1) 逆元Untitled_unrevised70 1495ms490600kbC++14395b2024-01-06 16:06:552024-01-06 16:06:55

Judging History

你现在查看的是测评时间为 2024-01-06 16:06:55 的历史记录

  • [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);
}

详细

Test #1:

score: 30
Accepted
time: 31ms
memory: 490576kb

Test #2:

score: 40
Accepted
time: 1495ms
memory: 490600kb

Test #3:

score: 0
Time Limit Exceeded