I know that (a/b)mod M = ab^-1 mod M
and also that when M is prime then b^-1 = b^(M-2)
I have to calculate (121/2)mod M where M = 1000000007 (1e9 + 7)
Using simple division: (121/2)modM = (60)mod M = 60%M = 60
Using modular Inverse: (121/2)mod M = ( (121 mod M ) * ( 2 ^(M-2) mod M) ) mod M.
2 ^(M-2) mod M here is 500000004 (link: http://www.cs.princeton.edu/~dsri/modular-inversion-answer.php?n=2&p=1000000007)
so the above expression becomes (121 mod M * 500000004)mod M = 60500000484 mod M = 500000064
What am i possibly doing wrong?