powered by
n
m
modinv(n, m)
NA
0 < n0 < m
n * n0 = 1 mod m
extGCD
modinv(5, 1001) #=> 801, as 5*801 = 4005 = 1 mod 1001 Modinv <- Vectorize(modinv, "n") mod((1:10)*Modinv(1:10, 11), 11) #=> 1 1 1 1 1 1 1 1 1 1
Run the code above in your browser using DataLab