Find all bases such that $P$ in those bases ends with the decimal representation of $Q$

34 Views Asked by At

Given two numbers $P$ and $Q$ in decimal. Find all bases such that $P$ in those bases ends with the decimal representation of $Q$.

I was going to write a code for this problem. The idea in my mind was: I would convert $P$ to other bases and check if P % pow(10, numberofdigits(B)) == B is true (code is in C++ syntax).

Well, I can check for some finite number of bases but how do I know where (after what base) to stop checking. I got stuck here.