You are viewing a single comment's thread. Return to all comments →
p%i = p - (p/i) * i (by definition of modulo. Note that all division are integer division)
p%i * inv[i] = p - (p/i) * i * inv[i] = p - (p/i)
inv[i] = inv[p%i] * p - (p/i)
Seems like cookies are disabled on this browser, please enable them to open this website
I agree to HackerRank's Terms of Service and Privacy Policy.
Ajob Subsequence
You are viewing a single comment's thread. Return to all comments →
p%i = p - (p/i) * i (by definition of modulo. Note that all division are integer division)
p%i * inv[i] = p - (p/i) * i * inv[i] = p - (p/i)
inv[i] = inv[p%i] * p - (p/i)