QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#667367#5. 在线 O(1) 逆元liuziao100 ✓5479ms82024kbC++23370b2024-10-22 22:31:082024-11-05 22:06:35

Judging History

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

  • [2024-11-05 22:06:35]
  • 管理员手动重测本题所有提交记录
  • 测评结果:100
  • 用时:5479ms
  • 内存:82024kb
  • [2024-10-22 22:31:17]
  • 评测
  • 测评结果:100
  • 用时:4855ms
  • 内存:81968kb
  • [2024-10-22 22:31:08]
  • 提交

answer

#include "inv.h"

const int kMaxN = 2e7 + 5;

int mod, iv[kMaxN];

void init(int p) {
  iv[1] = 1;
  ::mod = p;
  for (int i = 2; i <= 2e7; ++i) {
    iv[i] = 1ll * (mod - mod / i) * iv[mod % i] % mod;
  }
}

int inv(int x) {
  int coef = 1;
  for (; x > 2e7; x = mod % x) coef = 1ll * coef * (mod - mod / x) % mod;
  return 1ll * coef * iv[x] % mod;
}

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 243ms
memory: 81832kb

Test #2:

score: 20
Accepted
time: 762ms
memory: 81828kb

Test #3:

score: 30
Accepted
time: 2892ms
memory: 82024kb

Test #4:

score: 20
Accepted
time: 4508ms
memory: 81836kb

Test #5:

score: 20
Accepted
time: 5479ms
memory: 82024kb