QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#287480#5. 在线 O(1) 逆元acwing_gza100 ✓5812ms394540kbC++14262b2023-12-20 17:12:592024-11-05 21:56:22

Judging History

This is the latest submission verdict.

  • [2024-11-05 21:56:22]
  • 管理员手动重测本题所有提交记录
  • Verdict: 100
  • Time: 5812ms
  • Memory: 394540kb
  • [2023-12-20 17:12:59]
  • Judged
  • Verdict: 70
  • Time: 1349ms
  • Memory: 394428kb
  • [2023-12-20 17:12:59]
  • Submitted

answer

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

Details


Pretests


Final Tests

Test #1:

score: 10
Accepted
time: 816ms
memory: 394520kb

Test #2:

score: 20
Accepted
time: 1299ms
memory: 394468kb

Test #3:

score: 30
Accepted
time: 3456ms
memory: 394524kb

Test #4:

score: 20
Accepted
time: 5134ms
memory: 394540kb

Test #5:

score: 20
Accepted
time: 5812ms
memory: 394340kb