QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#775496#5. 在线 O(1) 逆元Physics212303100 ✓5345ms394504kbC++17233b2024-11-23 16:04:552024-11-23 16:04:55

Judging History

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

  • [2024-11-23 16:04:55]
  • 评测
  • 测评结果:100
  • 用时:5345ms
  • 内存:394504kb
  • [2024-11-23 16:04:55]
  • 提交

answer

#include "inv.h"
const int N=1e8;
static int P,a[N+1];
void init(int p){
  P=p,a[0]=a[1]=1;
  for(int i=2;i<=N;i++)
    a[i]=P-1ll*(P/i)*a[P%i]%P;
}
int inv(int x){
  if(x<=N)return a[x];
  return P-1ll*(P/x)*inv(P%x)%P;
}

詳細信息


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 692ms
memory: 394504kb

Test #2:

score: 20
Accepted
time: 1149ms
memory: 394300kb

Test #3:

score: 30
Accepted
time: 2985ms
memory: 394448kb

Test #4:

score: 20
Accepted
time: 4402ms
memory: 394500kb

Test #5:

score: 20
Accepted
time: 5345ms
memory: 394436kb