Add and Divide Problem issue - CodeChef Starters 13 Division 2 (Rated)

I tried Multiple ways using GCD etc. one of them was this Solution: 51695395 | CodeChef.
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 Solution: 51707373 | CodeChef 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?

I Got It

  • one issue was a == 1 & b ==1. then this would be wrong.
  • Also sum of a can be greater than 10^9