inverse modulo

can someone explain why this code works and theory behind it

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