QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#840212 | #5. 在线 O(1) 逆元 | Graygoo | 30 | 1476ms | 81824kb | C++14 | 693b | 2025-01-02 16:20:25 | 2025-01-02 16:20:26 |
Judging History
answer
#include<bits/stdc++.h>
//#include"inv.h"
using namespace std;
#define ll long long
const ll mod = 998244353;
const ll magic = 68996401;
int prime[]={2,3,5,7,11};
ll iv[10000005];
ll qpow(ll a,int w){
ll ans=1;
while(w){
if(w&1)ans=ans*a%mod;
w>>=1;a=a*a%mod;
}
return ans;
}
void init(int p){
iv[1]=1;
for(int i=2;i<=10000000;i++)iv[i]=(mod-iv[mod%i]*(mod/i)%mod)%mod;
return ;
}
int inv(int x){
ll ans=magic;x=x*magic%mod;
for(int i=0;i<5;i++){
while(x%prime[i]==0)ans=ans*iv[prime[i]]%mod,x/=prime[i];
}
if(x<=10000000)ans=ans*iv[x]%mod;
else ans=ans*qpow(x,mod-2)%mod;
return ans;
}
Details
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 113ms
memory: 81816kb
Test #2:
score: 20
Accepted
time: 1476ms
memory: 81824kb
Test #3:
score: 0
Time Limit Exceeded
Test #4:
score: 0
Time Limit Exceeded
Test #5:
score: 0
Time Limit Exceeded