this solution is WRONG!!!the test cases are not strong enough.
i doubt its correctness at the first glance, so i write a program to test it.
and your solution starts to give a wrong answer when n = 1694.
so WHY it's wrong?
take 30 for example, 30%2 == 30%3 == 30%5, the indices is moving at an improper occasion, and eventually
it will produce wrong answer.
Ugly Number II