I won't be able to offer full proofs here (lack of time ), but I'll offer you what I believe to be true. Oh yeah, I'm also assuming .
We want to solve where .
Here's my take:
Your solution will always be of the form (assuming a solution exists), where .
Now what's the value of ?
I claim is the smallest value in that satisfies .
So to find , I would just make a loop to scan all multiples of , until (or if) you find your solution.
Also note, if exists, it's guaranteed that .
Disclaimer: I won't have the time to prove these assertions, and they come from observations made from numerous and diverse examples I tried. If anyone else sees something wrong here, please say so!