inverse modulo

inverse
modulo

#1

can someone explain why this code works and theory behind it

inv[0]=inv[1]=1;
    for(i=2;i<=max;i++)
            inv* = mod - (((long long)mod/i)*inv[mod%i])%mod;

#2

http://discuss.codechef.com/questions/3433/modular-multiplicative-inverse