LightOJ – Necklace

Problem Name: Necklace
Judge: LightOJ
Algorithms & DS: GCD, Extended GCD, Binary Exponentiation, Modular Inverse