3
Calculates multiplicative inverse5
unsigned long modPow(unsigned long x, int y) {6
unsigned long tot = 1, p = x;8
if (y & 1) tot = (tot * p) % mod97;15
unsigned long seq[100001];16
unsigned int length = 0;17
unsigned long increment = 0;18
unsigned long mult = 1;20
ios_base::sync_with_stdio(false);24
void append(int val) {25
seq[length++] = (((mod97 + val - increment) % mod97) * modPow(mult, mod97 - 2)) % mod97;27
void addAll(int inc) {28
increment = (increment + inc % mod97) % mod97;32
mult = (mult * m % mod97) % mod97;33
increment = (increment * m % mod97) % mod97;36
int getIndex(int idx) {40
return ((seq[idx] * mult) % mod97 + increment) % mod97;