I tried Multiple ways using GCD etc. one of them was this CodeChef: Practical coding for everyone.
My concept was : (a*m)/b^n = 1
=> m = b^n/a
- so, for b==1 it will be “No” always
- else if we are able to find an integer value of m = b^n/a {rem = 0} then “YES” otherwise “NO”.
after the contest was over I was reading correct solns. what i found CodeChef: Practical coding for everyone this soln. also followed the same concept as I did but verdicts were different. Difference was I am terminating my loop after the value is more than 10^9.(But would this be an issue or was it possible that a can be added even after reaching 10^9 ) .
Is there a better solution to this problem?