URI -- 1028 (Collectable Cards)

Problem Link

Algorithm used Euclidean GCD (Click the link for Tutorial).  

Solution :