solve the number theory problem elegantly, the algorithm is exactly the tutotial algorithm, very gooood