QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#775521 | #5. 在线 O(1) 逆元 | Physics212303 | 100 ✓ | 5130ms | 394444kb | C++17 | 233b | 2024-11-23 16:08:17 | 2024-11-23 16:08:17 |
Judging History
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: 673ms
memory: 394440kb
Test #2:
score: 20
Accepted
time: 1127ms
memory: 394396kb
Test #3:
score: 30
Accepted
time: 2910ms
memory: 394380kb
Test #4:
score: 20
Accepted
time: 4261ms
memory: 394444kb
Test #5:
score: 20
Accepted
time: 5130ms
memory: 394444kb