I m learning Hashing from HERE , Now in this the topic “hash value of a substring”

```
hash(s[i..j]) = ( (hashvalue upto j - hasvalue upto i-1 ) / p^i ) mod m
hash(s[i..j]) = ( (hashvalue upto j - hasvalue upto i-1 ) * inversemod(p^i ) ) mod m
```

I m calcultaing prefix hashvalue (not suffix as many git repo use suffix (i m confusing in suffix so) ) Now I can easily calculate inversemod(p^i) by first calculating x = p^i mod m and then x^(m-2) mod m … fo for each power i it takes n(logn*logn) time , so how can precompute inverse of every p^i lesser than this time ?