Q:

Help with modulo arithmetic

How do you solve something like 7Xd =(congruent to) 1 mod 40?
find the smallest d that satisfies this equation

A:

Euler's theorem suggests that if you raise 7 to a large enough power, you find D. Powers of seven mod 40 are 1, 7, 9, 23, 1, ...,  so d is 23. 
D is unique as 40 and 7 are coprime (as 7 is prime). If it weren't unique, there would be two d1, d2 such that d1 != d2 and d1*7 == 1 == d2*7 (mod 40), so some value (d2-d1)*7 mod 40 is zero. I'm not sure how a general case might be found.

