Is there an efficient way to find two positive integers given their xor and product?

174 Views Asked by At

Is there an efficient way to find two positive integers given their bitwise exclusive or and product?

I saw this on quora, and wasn't able to come up with a good solution. Ideally, I would like a O(1) or O(number of bits) algorithm

An obvious way is to factor the product, using the xor to bound the factors, and seeing which factors when xored give the desired xor.

Also, I'm not sure what tags this should use besides factoring.