Advertisement
RaFiN_

Modular inverse of 1 to n in O(n) time

Jul 7th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.13 KB | None | 0 0
  1. you can calculate modular inverses to first n integers in O(n) time using this formula: inv[i] = (-(p+i-1)/i + inv[p%i] + p)%p;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement