A common problem in number theory is to find x given a such that:
a * x = 1 mod [n] 
Then x is called the inverse of a modulo n. 
Your goal is to code a function inverseMod wich take a and n as parameters and return x.
You may be interested by these pages:
http://en.wikipedia.org/wiki/Modular_multiplicative_inverse
http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm
a and n should be co-prime to have a solution, if it is not the case, you should return None (Python), nil (Ruby) or null (Javascript). 
a and n will be positive integers. The problem can easily be generalised to negative integer with some sign changes so we won't deal with them.
def inverseMod(a, m):
    r1, s1, r2, s2 = a, 1, m, 0
    while r2>0:
        q = r1//r2
        r1, s1, r2, s2 = r2, s2, r1-q*r2, s1-q*s2
    if r1==1:
        return s1%m


def inverseMod(a, m):
    r1, s1, r2, s2 = a, 1, m, 0
    while r2>0:
        q = r1//r2
        r1, s1, r2, s2 = r2, s2, r1-q*r2, s1-q*s2
    if r1==1:
        return s1%m

