How to solve ADADIG on spoj

maths
number-theory

#1

problem: LINK