subtract-and-multiply
Source: hackerearth
Difficulty: UNKNOWN_DIFFICULTY

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

SAMPLE INPUT
3
1 2
0 4
-1 1

SAMPLE OUTPUT
4
2
0


#__author__ = 'guluuu3'
from math import sqrt
def factors(n):
	return [(i,n/i) for i in range(1,int(sqrt(n))+1) if not n%i]
t=eval(input())
while(t):
	d,p=list(map(int,input().split()))
	flag=False
	for i,j in factors(p):
		if j-i==d:
			flag=True
			break
	if (flag==True):
		print(4 if j!=i else 2)
	else:
		print(4 if p==0 else 0)
	t=t-1






import sys
from math import sqrt

def isqrt(n):
	if n <= 0:
		return 0

	x = int(sqrt(n) * (1 + 1e-12))
	while True:
		y = (x + n // x) >> 1
		if y >= x:
			return x
		x = y

def solve():
	stdin = sys.stdin
	write = sys.stdout.write

	t = int(stdin.readline())
	for _ in range(t):
		D, P = list(map(int, stdin.readline().split()))

		ans = set()

		if D >= 0:
			r = D * D + 4 * P
			if r >= 0:
				rt = isqrt(r)
				if rt * rt == r:
					num = -D + rt
					if not num & 1:
						b = num // 2
						a = D + b
						ans.add((a, b))
						b = (-D - rt) // 2
						a = D + b
						ans.add((a, b))

					num = D + rt
					if not num & 1:
						b = num // 2
						a = -D + b
						ans.add((a, b))
						b = (D - rt) // 2
						a = -D + b
						ans.add((a, b))
		write("%d\n" % len(ans))

solve()


from math import sqrt

def is_perfect_square(y):
	if y < 0:
		return False
	x = int(sqrt(y))
	while x * x < y: x += 1
	while x * x > y: x -= 1
	return x * x == y

def f(d,p):
	y = d*d + 4*p
	if d < 0 or not is_perfect_square(y):
		return 0
	return 1 << (d>0) + (y>0)

for cas in range(eval(input())):
	d, p = list(map(int, input().strip().split()))
	print(f(d,p))


from math import sqrt
def factors(n):
	return [(i, n/i) for i in range(1, int(sqrt(n)) + 1) if not n%i]
for _ in range(int(input())):
    d, p = list(map(int, input().split()))
    found = False
    for i, j  in factors(p):
	  if j - i == d:
		found = True
		break
    if found:
	  print(4 if j != i else 2)
    else:
	  print(4 if p == 0 else 0)