Subtract and Multiply

4

4 votes
Problem

Tim likes Math. He likes it so much that he always brings his tablets with him and reads math e-books everywhere, even during parties.

Tim found an interesting exercise in one of the e-books he is reading. But you want him to join the party, so you decide to answer the question for him.

The problem is: Given D and P, how many ordered pairs of integers are there whose absolute difference is D and whose product is P? In other words, how many pairs of integers (A,B) are there such that:

|A−B|=D A×B=P

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?