Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?You are given a system of equations:   You should count, how many there are pairs of integers (a, b) (0 ≤ a, b) which satisfy the system.

A single line contains two integers n, m (1 ≤ n, m ≤ 1000) — the parameters of the system. The numbers on the line are separated by a space.

On a single line print the answer to the problem.

NoteIn the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.

n, m = map(int, raw_input().split())

total = 0
for a in range(n+1):

	b = n - a**2
	if b < 0:
		break

	if a + b**2 == m:
		total += 1

print total

n, m = map(int, input().split())
count = 0

for a in range(0, max(n, m) + 1):
    for b in range(0, max(n, m) + 1):
        if a ** 2 + b == n and a + b ** 2 == m:
            count += 1
print(count)

n,m=map(int,raw_input().split())
r=range(32)
print(sum(a*a+b-n==a+b*b-m==0 for a in r for b in r))

n, m = map(int,input().split())
c = []
for i in range(n+1):
	for j in range(m+1):
		if i**2 + j == n and i + j**2 == m:
			c.append(i)
			c.append(j)
if len(c) == 0:
	print(0)
else:
	print(len(c)//2)

t=raw_input()
t=t.split()
count=0
for a in range(0,1001):
    for b in range(0,1001):
        if (a**2)+b==int(t[0]):
            if a+(b**2)==int(t[1]):
                count+=1
print count

n,m=map(int,input().split(" "))
s=0
for i in range(max(n,m)+1):
    for j in range(min(n,m)+1):
        if i**2+j==n and j**2+i==m:
            s+=1
print(s)

n, m = map(int, input().split())
c = 0
for a in range(n+1):
    for b in range(n+1):
        if a * a + b == n and a+b*b==m:
            # print(a,b, a*a+b)
            c += 1
print(c)

n,m=map(int,input().split())
cnt=0
a,b=0,0
n,m=max(m,n),min(m,n)
step=0
while step*step<=n:
    if step*step<=n:
        a=step
        step+=1
    b=n-a*a
    if (m-b*b)==a:
        cnt+=1
print(cnt)

n,m=[int(i)for i in input().split()]
c=0
i=0
while i*i <= n:
    b=n-(i*i)
    if i+(b*b)==m:
        c+=1
    i+=1
print(c)

n , m = map(int,input().split())
count = 0
for i in range(101):
    a = i
    aa = a * a
    b = n - aa
    if a + (b * b) == m and b >= 0:
        count += 1

print (count)

n, m = map(int, raw_input().split())
print sum([1 for i in xrange(m+1) if i*i<=m and (m-i*i)**2+i == n])

import math as m
n,o=map(int,input().split())
count=0
if n>o:
    a=m.floor(m.sqrt(n))
    for i in range(a+1):
        b= n-pow(i,2)
        if i+pow(b,2)==o:
           count+=1
else:
    b=m.floor(m.sqrt(o))
    for i in range(b+1):
        a=o-pow(i,2)
        if pow(a,2)+i==n:
            count+=1
print(count)

n,m = map(int, raw_input().split())
z = max(n,m)
cnt = 0
for a in xrange(z+1):
    b = n - a**2
    if b>=0 and a + b**2 == m:
        cnt+=1
print cnt

import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("out.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)
t=1
# t=int(input())
for _ in range(t):
    n,m=l()
    ans=0
    for a in range(1001):
        for b in range(1001):
            if a*a+b==n and b*b+a==m:
                ans+=1
    print(ans)

n, m = list(map(int, input().split()))
min = min(n, m)
a = b = catch = 0

while a < min and b < min:
    a = a + 1
    if a ** 2 + b == n and a + b ** 2 == m:
        catch = 1
    elif a == min:
        b = b + 1
        if a == b == min:
            a = b
        else:
            a = 0

if n == int(1) and m == int(1):
    catch = 2
print(catch)

def r(): return raw_input().strip()
def ri(): return int(r().strip())
def riv(): return map(int, r().split())

from math import sqrt

def main():
    n,m = riv()
    count = 0
    for a in range(int(sqrt(n))+1):
        b = n - (a**2)
        if b >= 0 and b**2 + a == m:
            count += 1

    print count

if __name__ == "__main__":
    main()

t = input().split()
n = int(t[0])
m = int(t[1])

count = 0

for a in range(1001):
    for b in range(1001):
        if a**2 + b == n and b**2 + a == m:
            count += 1

print(count)

s=raw_input()
n,m=s.split(' ')
n,m=int(n),int(m)
q=0
for i in xrange(0,101):
    for y in xrange(0,101):
        if i**2+y==n and i+y**2==m:
            q+=1
print(q)

n,m=list(map(int, input().split(' ')))
k = 0
for a in range(100):
    for b in range(100):
        if a**2+b == n and a + b**2 == m:
            k+=1
print(k)

n,m = map(int,raw_input().split())
ans=0
for i in range(2000):
	for j in range(2000):
		if i*i + j == n and i + j*j == m: ans+=1
print ans

n,m=map(int,input().split())
ans=0
for i in range(1001):
    for j in range(1001):
        if (i*i+j==n and i+j*j==m):
            ans+=1
print(ans)

import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
                  log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
    return(int(input()))

def inlist():
    return(list(map(int, input().split())))

def instr():
    s = input()
    return(list(s[:len(s)]))

def invr():
    return(map(int, input().split()))

n, m = invr()
c = 0
for i in range(n+1):
    for j in range(m+1):
        if i*i + j == n and i + j*j == m:
            c += 1
print(c)

n,m = map(int,raw_input().split())
count = 0
for i in range(1001):
    if (n - i*i) >= 0  and (m - i) == (n - i*i)*(n - i*i):
        count += 1
print count

flag=int()
flag=0
n,m = map(int,input().split())
for i in range(n+1):
        for j in range(m+1):
                if i*i+j==n and i+j*j==m:
                        flag=flag+1
print(flag)

n , m = map(int , input().split())
cnt = 0

for i in range(min(n , m) + 1):
    for j in range(min(n,m) + 1):
        if (i * i) + j == n and (j * j) + i == m:
            cnt += 1
print(cnt)

n,m=map(int,input().split())
c=0
for i in range(0,1001):
     for j in range(0,1001):
          if i*i+j==n and i+j*j==m:
                   c=c+1
print(c)

__author__ = 'Esfandiar'
from math import sqrt
n,m = map(int,input().split())
b = res = 0
nn=n
while n:
    yy=sqrt(n)
    if int(yy) == yy and yy+(b**2) == m:
        if nn ==m and yy!=b:
            res+=2
        else:
            res+=1
    b+=1
    n-=1
print(res)

n, m = map(int, input().split())
pairs = 0

for i in range(max(n,m)+1):
    for j in range(max(n,m)+1):
        if i**2 + j == n and j**2 + i == m:
            pairs += 1

print(pairs)

# DON'T USE PYTHON FOR RECURSION
# TRY PYPY
import math
import operator
import sys
from collections import Counter, defaultdict
from math import ceil, floor, pi, sin, sqrt
from sys import exit, stdin, stdout

def main():
    # stdin = open('.in')
    n, m = map(int, stdin.readline().strip().split(' '))
    ans = 0
    for a in range(1001):
        for b in range(1001):
            ans += a * a + b == n and a + b * b == m
    print ans

main()

n,m=map(int,raw_input().split())
print sum([i==n-(m-i*i)**2 for i in range(n+1) if m>=i*i])

n, m = [int(e) for e in (input().split())]
ans = 0

for a in range (33):
        b = n - a**2
        if a + (n-a**2)**2 == m and b >= 0:
            ans += 1
print (ans)

n, m = map(int, input().split())
highest = 0
count = 0

if n > m:
    highest = n
else:
    highest = m

for i in range(0, highest + 1):
    if i**2 + n-i**2 == n and i + (n-i**2)**2 == m and n-i**2 >=0:
        count += 1

print(count)

n,m = map(int,input().split())
a = 0
for i in range(0, 1000):
    for j in range(0, 1000):
        if i * i + j == n and j * j + i == m:
            a = a + 1
print(a)

t=raw_input()
t=t.split()
count=0
for a in range(0,1001):
    for b in range(0,1001):
        if (a**2)+b==int(t[0]):
            if a+(b**2)==int(t[1]):
                count+=1
print count

s = input()

n,m = s.split()

a = int(n)**0.5

a = int(a)
temp = a

pair = 0
while a>=0:
    b = int(n) - a**2
    if int(a) + b**2 == int(m):
        pair +=1
        a = int(a) - 1
        continue
    else:
        a= int(a)-1
        continue

"""
flag = 0
while flag == 0 :
    temp += 1
    b = int(n) - temp**2
    if int(temp) + b**2 == int(m):
        pair += 1
        continue
    elif int(temp) + b**2 < int(m):
        continue
    else:
        flag = 1
"""
print (pair)

a = [int(i) for i in raw_input().split(' ')]
res = 0
for i in range(max(a[0],a[1])+1):
               for j in range(max(a[0],a[1])+1):
                              if (i**2 + j == a[0]) and (j**2 + i == a[1]):
                                  res +=1
print(res)

def count(n, m):
    c = 0
    r = n
    if m < n:
        r = m
    a = 0
    while a <= r:
        b = n - a ** 2
        if b >= 0 and a + b ** 2 == m:
            c = c + 1
        a = a + 1
    return c

n, m = map(int, input().split())
count = count(n, m)
print(count)

n, m = [int(e) for e in (input().split())]
ans = 0

for a in range (int(n**0.5)+1):
        b = n - pow(a, 2)
        if b >= 0 and a + pow(b, 2) == m:
            ans += 1
print (ans)

n, m = map(int, input().split())
ans = 0

l = []
a = int(n ** 0.5)
for i in range(a+1):
    c = n - i ** 2
    t = (i, c)
    l.append(t)

for j in l:
    if j[0] + j[1] ** 2 == m:
        ans += 1

print(ans)

m,n=map(int,raw_input().split(" "))
a=count=0
while a<=m:
    if (a+pow(a,4)+n*n-2*n*a*a)==m:
        if n-a*a>=0:
            count+=1
    a+=1
print count

n, m = [int(x) for x in input().split()]
count = 0
mn = min(n, m)
for a in range(0, mn + 1):
    for b in range(0, mn + 1):
        if (a * a + b == n) and (a + b * b == m):
            count += 1
print(count)

n,m=(map(int,input().split()))
ans=0
for i in range(32):
    for j in range(32):
        if i**2+j==n and i+j**2==m:
            ans+=1
        #print(i,j)
print(ans)

#!/usr/bin/python
from __future__ import division
from sys import stdout,stdin
from copy import copy,deepcopy
import math

def solve():
    n,m=map(int,raw_input().split())
    counter=0
    for a in xrange(int(math.ceil(1000**0.5))+1):
        for b in xrange(int(math.ceil(1000**0.5))+1):
            #if a*b+1==(n/m)*b:
            #if a+(b/a)==(n/a) and (a/b)+b==(m/b):
            if a**2+b==n and a+b**2==m:
                counter+=1
    return counter

print solve()

n,m=list(map(int,input().split()))
count=a=0
while a*a<=n:
    b=0
    while b*b<=m:
        if a*a+b==n and a+b*b==m:
            count+=1
        b+=1
    a+=1
print(count)

inputs = raw_input().split(" ");
n = int(inputs[0]);
m = int(inputs[1]);
cnt = 0;
for i in range(1001):
	for j in range(1001):
		if ((i * i) + j) == n and (i  + (j *j) ) == m : cnt += 1;

print cnt;

#!/usr/bin/env python
# coding: utf-8

# In[204]:

# # n = int(input())
# # line = list(map(int, input().split()))
# # line = list(str(input()))

# In[406]:

line = list(map(int, input().split()))

# In[407]:

m, n = line[0], line[1]
sum_val = m + n
n_pair = 0

for i in range(sum_val//2 + 1):
    for j in range(sum_val//2 +1):
        equ1 = i**2 + j
        equ2 = i + j**2
        if equ1 == m and equ2 == n:
            n_pair += 1

print(n_pair)

# In[375]:

n, m = map(int, input().split())
ans = 0
for a in range(n + 1):
    for b in range(n + 1):
        ans += (a * a + b == n) & (a + b * b == m)
print(ans)

import sys
import math

n,m = map(int,raw_input().split())

count = 0
k = max(n,m)
for i in range(k+1):
    for j in range(k+1):
        if (i**2+j)==n and (j**2+i)==m:
            count+=1

print(count)

import math
n,m = map(int,input().split())
count=0
for i in range(int(math.sqrt(n))+1):
    for j in range(int(math.sqrt(m))+1):
        if (i*i)+j == n and i+(j*j) == m:
            count+=1
print(count)

import bisect
from collections import defaultdict
from collections import deque
import math
import re

def ni():
    return int(raw_input())

def nis():
    return map(int, raw_input().split())

def si():
    return raw_input()

def sis():
    return raw_input().split()

n, m = nis()

ans = 0
for a in range(0, int(math.ceil(math.sqrt(n))) + 1):
    for b in range(0, int(math.ceil(math.sqrt(m))) + 1):
        if a** 2 + b == n and a + b **2 == m:
            ans += 1

print ans

N,M=map(int,input().split())
ans=0
if N>=M:
    for i in range(N+1):
        j=N-(i**2)
        if i+(j**2)==M and j>=0:
            ans+=1
else:
    for i in range(M+1):
        j=M-(i**2)
        if i+(j**2)==N and j>=0:
            ans+=1

print(ans)

#!/usr/bin/env python
# http://acm.zhihua-lai.com

n, m = map(int, raw_input().split(' '))

x = 0
for a in xrange(0, int(n ** 0.5) + 1):
    b = n - a * a
    if a + b * b == m:
        x += 1

print x

ans = 0
n, m = map(int, input().split())
for i in range(n+1):
    for j in range(m+1):
        if (i*i+j) == n and (j*j+i)== m :
            ans+=1
print ("%d" % ans)

count = 0
n,m = map(int, input().split())
for a in range(0,max(int(pow(n, 0.5)), m)+1):
    for b in range(0, max(int(pow(m, 0.5)), n)+1):
        if (pow(a,2)+b == n) and (pow(b,2) + a == m):
            count += 1
print(count)

n, m = map(int, input().split())
count = 0
for i in range(1001):
    for j in range(1001):
        if i**2+j == n and i+j**2 == m:
            count+=1
print(count)

n, m = [int(e) for e in (input().split())]
ans = 0

for a in range (33):
        b = n - a**2
        if a + (n-a**2)**2 == m and b >= 0:
            ans += 1
print (ans)

n, m = map(int, raw_input().split())
print sum([a**2 + b == n and a + b**2 == m for a in xrange(n+1) for b in xrange(m+1)])

n,m= list(map(int,input().split()))
count = 0
for i in range(max(n,m)+1):
    for j in range(max(n,m)+1):
        if ((i*i)+j == n) and (i+(j*j) == m):
            count += 1
print(count)

n,m = map(int,raw_input().split())
count = 0
for i in range(1001):
    if (n - i*i) >= 0  and (m - i) == (n - i*i)*(n - i*i):
        count += 1
print count

import math
def main():
    n,m = map(int,input().split())
    c = 0
    for i in range(0,int(math.sqrt(n) + 1)):
        a = i
        b = n - a*a
        if b*b + a == m:
            c += 1
    print(c)

main()

n,m = map(int, raw_input().split())
z = max(n,m)
cnt = 0
for a in xrange(z+1):
    b = n - a**2
    if b>=0 and a + b**2 == m:
        cnt+=1
print cnt

n, m = map(int, input().split())
r, c = (max(n,m)+1)//2+1, 0
for a in range(r):
    for b in range(r):
        if a**2+b==n and a+b**2==m: c+=1
print(c)

n, m = map(int,input().split())
c = []
for i in range(n+1):
	for j in range(m+1):
		if i**2 + j == n and i + j**2 == m:
			c.append(i)
			c.append(j)
if len(c) == 0:
	print(0)
else:
	print(len(c)//2)

n,m = map(int,raw_input().split())
c = 0
for i in xrange(n+ 1):
    for j in xrange(m+ 1):
        if i*i + j == n and i + j*j == m:
            c += 1

print(c)

import sys
import math

n, m = [int(x) for x in (sys.stdin.readline()).split()]

if(n > 992 and m > 992):
    print(0)
    exit()

if(n >= m):
    k = int(math.sqrt(n))
    t = n - (k ** 2)

    res = 1
    if((t ** 2) + k == (t) + (k ** 2) and t != k):
        res += 1

    if((t ** 2) + k == m):
        print(res)
    else:
        print(0)
elif(m > n):
    k = int(math.sqrt(m))
    t = m - (k ** 2)

    if((t ** 2) + k == n):
        print(1)
    else:
        print(0)

import itertools
I = lambda : map(int, raw_input().split())

def main():
    n, m = I()
    print sum(a**2+b==n and a+b**2==m for a, b in itertools.product(range(1001), repeat=2))

if __name__ == '__main__':
    main()

numbers=[int(n) for n in input().split()]
mx,mn=max(numbers),min(numbers)
pair=0
for i in range(0,int(pow(mx,0.5))+1):
    for q in range(0,mx-(i*i)+1):
        if i*i+q==mx and i+q*q==mn:
            pair+=1
print(pair)

n, m = map(int, input().split())
if (m + n) < 10:
    x = (m + n) ** 2
else:
    x = max(n, m)
a = 0
b = 0
count = 0
for i in list(range(x)):
    for j in list(range(x)):
        if a ** 2 + b == n and a + b ** 2 == m:
            count += 1
            b += 1
        else:
            b += 1
    a += 1
    b = 0
print(count)

n, m = map(int, input().split())
ans = 0
for a in range(n + 1):
    for b in range(n + 1):
        if a * a + b == n:
            if a + b * b == m:
                ans += 1
print(ans)

import itertools
n,m = map(int,raw_input().split())
print sum(a**2+b==n and a+b**2==m for a,b in itertools.product(range(99),repeat=2))

from sys import stdin

line = stdin.readline().split()
n = int(line[0])
m = int(line[1])
pairs = 0

for a in range(0, 32):
    for b in range(0, 32):
        if (a*a + b == n) and (a + b*b == m):
            pairs += 1

print pairs

n,m=map(int,input().split())
s=0
for b in range(m+1):
    for a in range(n+1):
        if((a**2+b ==n) and (a+b**2 ==m)):
            s=s+1
print(s)

c=0
n,m=map(int,input().split())
p=max(m,n)
for i in range(p+1):
  if ((i*i+abs(n-(i*i)))==n) and ((i+abs(n-(i*i))*abs(n-(i*i)))==m):
    c=c+1
print(c)

import math
string = input()
numbers = string.split(' ')
a = int(numbers[0])
b = int(numbers[1])
solutions = 0
for x in range(int(math.sqrt(a)) + 1):
    y = a - x ** 2
    if x + y ** 2 == b:
        solutions += 1
print(solutions)

###Codeforces problem 456A###

n, m = map(int, raw_input().split())

ans = 0
for a in range(32):
    b = n - a * a
    if (a + b * b) == m and b >= 0:
        ans += 1

print ans

n, m = map(int, input().split())
count = 0
for i in range(max(n, m) + 1):
    for j in range(max(n, m) + 1):
        if i * i + j == n and i + j * j == m:
            count += 1
print(count)

import math
n,m=map(int,input().split())
k=int(max(math.sqrt(n),math.sqrt(m)))
c=0
for i in range(k+1):
    for j in range(k+1):
        if(i*i+j == n and j*j+i==m):
            c+=1
print(c)

#214A
[n,m] = list(map(int,input().split()))
s = 0
for i in range(1001):
    for j in range(1001):
        if i**2+j==n and i+j**2==m:
               s+=1
print(s)

n,m = map(int, raw_input().split())
print sum([1 for a in range(n+1) if n >= a**2 and m == a + (a**2 - n)**2])

n, m = map(int, input().split())
count = 0

for a in range(0, max(n, m) + 1):
    for b in range(0, max(n, m) + 1):
        if a ** 2 + b == n and a + b ** 2 == m:
            count += 1
print(count)

def form(a, b, n, m):
    if((a**2)+b == n and a+(b**2)==m):
        return True
    else:
        return False
inp = list(map(int,input().split()))
n = inp[0]
m = inp[1]
smal = 0
big = 0
count = 0
if(n > m):
    smal = m
    big = n
else:
    smal = n
    big = m
for a in range(0, big+1):
    for b in range(0, big+1):
        if(form(a, b, n, m)):
            count += 1
print(count)

import sys

delers=[]

t=[int(x) for x in sys.stdin.readline().split()]

n,m=t[0],t[1]

result=0

for a in range(n+1):
    for b in range(m+1):
        if a*a+b==n and b*b+a==m:
            result+=1

print result

n,m=map(int,input().split())
r=range(32)
print(sum(a*a+b-n==a+b*b-m==0 for a in r for b in r))

#!/usr/bin/python

def ir():
    return int(raw_input())

def ia():
    line = raw_input()
    line = line.split()
    return map(int, line)

n, m = ia()

ans = 0
for a in range(1005):
    for b in range(1005):
        if a*a + b==n and a + b*b==m:
            ans = ans + 1

print ans

n, m = list(map(int, input().split()))
count = 0
a, b = 0, 0
while a ** 2 <= n:
    b = n - a ** 2
    if a ** 2 + b == n and a + b ** 2 == m:
        count += 1
        a += 1
    else:
        a += 1
print(count)

import fileinput as f
import math

for line in f.input():
    if f.lineno() == 1:
        [n, m] = map(int, line.split())

a0 = 0
temp = int(math.sqrt(n))
if temp < m:
    af = temp
else:
    af = m

count = 0

def isint(x):
    return True if x - int(x) == 0 else False

for ai in range(a0, af+1):
    b = math.sqrt(m - ai)
    if isint(b):
        a = math.sqrt(n - b)
        if isint(a):
            count += 1

print count

(m,n) = map(int, raw_input().split())
x = m if m>n else n
print sum(((a*a)+b == n) and (a + (b*b) == m) for a in range(x+1) for b in range(x+1))

n, m = map(int, input().split())
count = 0
for i in range(1001):
    for j in range(1001):
        if i**2+j == n and i+j**2 == m:
            count+=1
print(count)

n, m = [int(x) for x in input().split()]
count = 0
mn = min(n, m)
for a in range(0, 1000):
    for b in range(0, 1000):
        if (a * a + b == n) and (a + b * b == m):
            count += 1
print(count)

import math

n,m=list(map(int,input().split()))
a=max(n,m)
b=min(n,m)
c=int(math.sqrt(a))
r=a-(c*c)
if a==1 and b==1:
	print("2")
elif r==0:
	print("1")
elif c+(r*r)==b:
	print("1")
else:
	print("0")

n,m=map(int, input().strip().split())

res = 0

for a in range(0, 1000 ) :
	for b in range(0, 1000)   :
		if (a**2 + b == n) and (a + b**2 == m):
			res += 1
print(res )

a = sorted(list(map(int, input().split())))
counter = 0
for i in range(int(a[0] ** .5) + 1):
    if (a[0] - i ** 2) ** 2 + i == a[1]:
        counter += 1
print(counter)

n, m = list(map(int, input().split()))
min = min(n, m)
a = b = catch = 0

while a < min and b < min:
    a = a + 1
    if a ** 2 + b == n and a + b ** 2 == m:
        catch = 1
        print(catch)
    elif a == min:
        b = b + 1
        if a == b == min:
            a = b
        else:
            a = 0

if catch == 0:
    print('0')

N,M=map(int,input().split())
ans=0
if N>=M:
    for i in range(1,N+1):
        j=N-(i**2)
        if i+(j**2)==M:
            ans+=1
else:
    for i in range(1,M+1):
        j=M-(i**2)
        if i+(j**2)==N:
            ans+=1

print(ans)

from itertools import combinations
x,y=map(int,input().split())
l=[i for i in range(1000)]
p=list(combinations(l,2))
c=0
for i in range(len(p)):
    a = []
    for j in range(1):
        if (p[i][j]**2 + p[i][j+1]==x and p[i][j] + p[i][j+1]**2==y) or (p[i][j]**2 + p[i][j+1]==y and p[i][j] + p[i][j+1]**2==x):
            a.append(p[i][j])
            a.append(p[i][j+1])
            c +=1
if c>0:
    print(c)
else:
    print(0)

lis = list(map(int,input().split()))
lis.sort()
if lis[0]**2 == lis[1]:
    print(1)
elif lis[0]*2==lis[1]:
    print(1)
else:
    print(0)

n, m = map(int, input().split())
count = 0
for i in range(1001):
    if n**2 - 2*n*i**2 + i**4 - m + i == 0 and (n - i**2) % 1 == 0:
        count += 1
print(count)

import math

n,m=list(map(int,input().split()))
a=max(n,m)
b=min(n,m)
c=int(math.sqrt(a))
r=a-(c*c)
if r==0:
	print("1")
elif c+(r*r)==b:
	print("1")
else:
	print("0")

n,m = map(int,input().split())
c = 0
for a in range(-35,35):
    for b in range(-35,35):
        if a**2 + b == n:
            if b**2 + a == m:
                c += 1
print(c)

import sys
import math

n,m = map(int,raw_input().split())

count = 0
k = max(n,m)
for b in range(k+1):
    if m>=b**2 and b== n - (m-b**b)**2:
        count+=1

print(count)

# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# from math import *
# from itertools import *
# import random
n, m = map(int, input().split())
total_ = 0
for i in range(0, (n*n) + 1):
    b = n - i*i
    if b * b == m - i:
        total_ += 1
    else:
        continue
print(total_)

k = raw_input()
k = k.split()

n = int(k[0])
m = int(k[1])

ans = 0

for i in range(0, n+1):
	j = n - i**2
	if (i + j**2 == m):
		ans += 1

print ans

import  math
__author__ = 'EvgeniyVO1'

str = raw_input("input first number n=")

st = str.split(" ")

n = int(st[0])

m = int(st[1])

lim = int(math.sqrt(float(n)))

eq = []
count = 0
for i in range(0,lim):
    for j in range(0,m):
        if ((i*i+j == n) and (i+j*j == m)):
            count = count+1

print count

import math

def get_primes(prime_supr):

    is_prime = [0]*2 + [1]*prime_supr

    for i in range(2,int(math.sqrt(prime_supr)) + 1):
        if is_prime[i]:
            for j in range(i * i, prime_supr + 1, i):
                is_prime[j] = 0

    return is_prime

get_int = lambda: map(int, input().split())

n, m = get_int()

print([0, 1][m >= math.sqrt(n) and n >= math.sqrt(m)])

#!/usr/bin/python
from __future__ import division
from sys import stdout,stdin
from copy import copy,deepcopy
import math

def solve():
    n,m=map(int,raw_input().split())
    counter=0
    for a in xrange(n+1):
        for b in xrange(m+1):
            if a==0:
                if b==n and b**2==m:
                    counter+=1
            elif b==0:
                if a**2==n and a==m:
                    counter+=1
            #if b*a+b==(n/m)*b and a+(b*a)==(m/n)*a:
            elif a+(b/a)==(n/a) and (a/b)+b==(m/b):
                counter+=1
    return counter

print solve()

n,m=map(int,input().split())
c=0
for a in range(n):
	b=n-a*a
	if a+b*b==m:
		c+=1
print(c)

n,m = [int(x) for x in input().split()]

ans = 0
for a in range(max(n,m)):
    for b in range(max(n,m)):
        if a**2 + b == n and a + b**2 == m:
            ans += 1

print(ans)

def solved(n,m):
    ma = max(n,m)
    #print(ma)
    count = 0
    for i in range(ma):
        b = n-i*i
        if i + b*b == m:
            count += 1
    return count
if __name__ == '__main__':
    n,m = map(int,input().split())
    print(solved(n,m))

s = raw_input

n, m = map(int, s().split())

c = 0
for i in range(max(m, n)):
    for j in range(max(m, n)):
        if i**2+j == n and i+j**2==m:
            c+=1
print c

#!/usr/bin/env pypy
from __future__ import division, print_function
from collections import defaultdict, Counter, deque
from future_builtins import ascii, filter, hex, map, oct, zip
from itertools import imap as map, izip as zip, permutations, combinations, combinations_with_replacement,product
from __builtin__ import xrange as range
from math import ceil, factorial, log,tan,pi,cos,sin,radians
from _continuation import continulet
from cStringIO import StringIO
from io import IOBase
import __pypy__
from bisect import bisect, insort, bisect_left, bisect_right
from fractions import Fraction
from functools import reduce
from decimal import *
import string
import sys
import os
import re
inf = float('inf')
mod_ = int(1e9) + 7
mod = 998244353

def factors(n):
    from functools import reduce
    return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def sieve(n):
    arr=[1]*n
    for i in range(2,int(n**0.5)+1):
        if arr[i]==1:
            for j in range(i,n,i):
                arr[j]=i
    return arr

def main():
    cnt=0
    n,m=list(map(int,input().split()))
    for i in range(1,1001):
        for j in range(1,1001):
            if i**2+j==n and i+j**2==m:
                cnt+=1

    print(cnt)

# region fastio

BUFSIZE = 8192

class FastI(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = StringIO()
        self.newlines = 0

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count("\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

class FastO(IOBase):
    def __init__(self, file):
        self._fd = file.fileno()
        self._buffer = __pypy__.builders.StringBuilder()
        self.write = lambda s: self._buffer.append(s)

    def flush(self):
        os.write(self._fd, self._buffer.build())
        self._buffer = __pypy__.builders.StringBuilder()

def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

def gcd(x, y):
    while y:
        x, y = y, x % y
    return x

sys.stdin, sys.stdout = FastI(sys.stdin), FastO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

n,m=map(int,input().split())
k=0
for i in range(max(n,m)):
    b=i
    a=(n-b)**0.5
    if m-b**2==a:
        k+=1
print(k)

n,m=map(int,raw_input().strip().split())
cou=0
for i in range(m):
	if (m-(i*i))**2==n-i:cou+=1
	if n==m and n!=1000:cou=2
print cou

n, m = raw_input().split()
n, m = int(n), int(m)
t = 0
for a in range(0, n+1) :
    b = n - a**2
    if b == int(b) and b**2 + a == m :
        t += 1
print t

(N, M) = [int(x) for x in input().split()]
count = 0
for a in range(max(N, M)):
    for b in range(max(N, M)):
        if a + (b ** 2) == M and (a**2) + b == N:
            count += 1

print(count)

from sys import stdin

line = stdin.readline().split()
m = line[0]
n = line[1]
pairs = 0

for a in range(0, 32):
    for b in range(0, 32):
        if (a**2 + b == n) and (a + b**2 == m):
            pairs += 1

print pairs

a, b=sorted(map(int, input().split()))
g=max(a, b)
f=min(a, b)
i=1
while(i**2<=b):
  i=i+1
h=i-1
x=b-h**2
cnt=0

if h**2+x==b and x**2+h==a:
  cnt+=1
  print(cnt)
elif (a==1 and b==1):
  print("2")
else:
  print("0")

#*+++++++++++++++++++++
# * Written By --------
# * Boddapati Mahesh  **
# * IIIT Hyderabad *****
# */
n,m=map(int,raw_input().split())
count=0
for i in range(0,1001):
    for j in range(0,1001):
        if( i*i+j ==n and i+j*j==m):
            print i,j
            count+=1
print count

n,m=map(int,input().split())
count=0
a=0
b=0
while a**2+b!=n or a+b**2!=m:
    a+=1
    count+=1
    if a==32:
        a=0
        b+=1
    if a==31 and b==32:
        print(0)
        break
print(1)

t = input().split()
n = int(t[0])
m = int(t[1])

count = 0

for a in range(1,1001):
    for b in range(1,1001):
        if a**2 + b == n and b**2 + a == m:
            count += 1

print(count)

import math

n,m=list(map(int,input().split()))
a=max(n,m)
b=min(n,m)
c=int(math.sqrt(a))
r=a-(c*c)
if r==0:
	print("1")
elif c+(r*r)==b:
	print("1")
else:
	print("0")

# coding: utf-8
from math import sqrt

def tim_nghiem(n, so):
    nghiem = sqrt((n - so))
    nghiem_2 = int(nghiem)
    if nghiem == float(nghiem_2):
        return nghiem
    else:
        return None

if __name__ == '__main__':
    n, m = input().split(' ')
    n = int(n)
    m = int(m)
    mang_n = []
    for so_a in range(n + 1):
        if tim_nghiem(n, so_a):
            b = tim_nghiem(n, so_a)
            if tim_nghiem(m, b) is not None:
                a = tim_nghiem(m, b)
                if int(a) == int(so_a):
                    mang_n.append([so_a, b])
    print(len(mang_n))

n,m = map(int,raw_input().split())

count = 0
for a in range(max(n,m)):
    for b in range(max(n,m)):
        if a*a+b == n and a+b*b == m:
            count += 1

print count

#hello
c=0
n,m=map(int,input().split())
p=max(m,n)
for i in range(0,p+1):
  if (i*i+(n-(i*i)))==n and (i+(n-i)*(n-i))==m:
    c=c+1
print(c)

def solve(n, m):
    return sum(1 for b in range(n + 1)
                 for a in range(m + 1)
                 if a*a + b == n and b*b == m)

def main():
    n, m = list(map(int, input().split()))
    print(solve(n, m))

main()

import sys
import math

n, m = [int(x) for x in (sys.stdin.readline()).split()]

if(n > m):
    k = int(math.sqrt(n))
    t = n - (k ** 2)

    if((t ** 2) + k == m):
        print(1)
    else:
        print(0)
elif(m > n):
    k = int(math.sqrt(m))
    t = m - (k ** 2)

    if((t ** 2) + k == n):
        print(1)
    else:
        print(0)
else:
    print(2)

n, m = map(int, input().split())
p = [i for i in range(round(max(n, m) ** 0.5) + 1)]
count = 0
if n == m and n <= 2:
    print(2)
else:
    for i in p:
        for j in range(len(p) - 1):
            if p[j + 1] ** 2 + i == n and p[j + 1] + i ** 2 == m:
                count += 1
    print(count)

n, m = map(int, input().split())
if n + m > 0 and n * m == 0:
	print(0)
elif n + m == 0:
	print(1)
else:
	a = 0
	b = 0
	flag = 0
	while (a ** 2 + b < n or b ** 2 + a < m) and flag == 0:
		while a ** 2 + b < n or b ** 2 + a < m:
			a += 1
		if a **2 + b == n and b ** 2 + a == m:
			flag = 1
		else:
			a = 0
			b += 1
	if a ** 2 + b == n and b ** 2 + a == m:
		if n == m:
			print(2)
		else:
			print(1)
	else:
		print(0)

n, m = map(int, raw_input().split())
s = 0

for a in range(10000):
        b = n - a*a
        if b >= 0 and a + b * b == m:
                s += 1
                print a, b

print s

n,m = map(int,raw_input().split())
pairs = 0
for a in range (0,1001):
    b = n-(a*a)
    if (a + b*b == m):
        pairs += 1
print pairs

n, m = raw_input().split()
n, m = int(n), int(m)
t = 0
for a in range(0, n) :
    b = n - a**2
    if b == int(b) and b**2 + a == m :
        t += 1
print t

import math
lst=[]
z=list(map(int,input().split()))
for i in range(1,int(math.sqrt(max(z)))+1):
    x=z[0]-(i*i)
    if i+(x*x)==z[1]:
       if (i,x) not in lst:
          lst.append((i,x))
    v=z[1]-(i*i)
    if (v*v)+i==z[0]:
        if (v,i) not in lst:
            lst.append((v,i))
print(len(lst))

n,m=map(int,input().split())
cnt=0
a,b=0,0
while a+(b**2)!=m and (a**2)+b!=n:
    if cnt**cnt<n:
        cnt+=1
        a=cnt
    if cnt**cnt>=n:
        b=n-a**2
if m-b**2==a:
    print(1)
else:
    print(0)

import sys

[n,m] = [int(x) for x in sys.stdin.readline().split()]
squares = [x*x for x in range(32)]
singles = [x for x in range(32)]
set_singles = set(singles)
counter = 0
for x in range(len(squares)):
    b = n - squares[x]
    if b*b + singles[x] == m:
        counter += 1
print counter

# http://codeforces.com/problemset/problem/214/A
n, m  = map(int, input().split())
nm    = max(n,m)
count = 0

for a in range(0,nm-2):
	for b in range(a+1,nm):
		sum_a2b = a*a + b
		sum_ab2 = a + b*b

		if ((sum_a2b == n) and (sum_ab2 == m)) or ((sum_a2b == m) and (sum_ab2 == n)):
			count += 1

if (n == 1 and m == 1):
	print('2')
else:
	print(count)

n,m=map(int,input().split())
i=0
t=[]
s=[]
ch=0
while i**2<=n:
    t.append(i)
    i+=1
for i in range(len(t)):
    s.append(n-t[i]**2)
for i in range(len(t)):
    if t[i]+s[i]**2==m:
        ch+=1
print(s)

#!/usr/bin/env python
from sys import stdin
from math import modf

n, m = map(float, stdin.readline().split() )
count = 0
t = n
while(n):
    l = modf(n ** 0.5)
    if l[0] == 0:
        if l[1] + ((t-n) ** 2) == m:
            count += 1
    n -= 1
print count

def form(a, b, n, m):
    if((a**2)+b == n and a+(b**2)==m):
        return True
    else:
        return False
inp = list(map(int,input().split()))
n = inp[0]
m = inp[1]
smal = 0
big = 0
count = 0
if(n > m):
    smal = m
    big = n
else:
    smal = n
    big = m
for a in range(0, big):
    for b in range(0, big):
        if(form(a, b, n, m)):
            count += 1
print(count)

n, m = [int(x) for x in input().split(' ')]
a, b = 0, 0
res = 0
for i in range(0, m+n):
	for j in range(i, m+n):
		# print("pair({}, {})".format(i, j))
		first = (i ** 2) + j
		second = i + (j ** 2)

		if (first == n and second == m) or (first == m and second == n):
			res += 1

print(res)

from collections import defaultdict
n, m = [int(i) for i in input().split(" ")]
ct = 0
#dic = defaultdict(tuple)
'''for a in range(1001):
    b = n - a*a
    if b>=0 and a>=0 and a + b*b == m:
        ct+=1

if n==m:
    ct -= 1
print(ct)
'''
for a in range(1001):
    for b in range(a,1001):
        if a*a+b == n and a + b*b == m:
            ct+=1
print(ct)

n, m = raw_input().split()
n, m = int(n), int(m)
t = 0
for a in range(0, n+1) :
    b = n - a**2
    if b**2 + a == m and b > 0 :
        t += 1
print t

n,m = map(int, raw_input().split())
print sum([1 for a in range(n) if n >= a**2 and m == a + (a**2 - n)**2])

import sys, collections
input = sys.stdin.readline

n, m = map(int, input().split())

if n % m == 0 or m % n == 0:
    print(1)
else:
    print(0)

from collections import defaultdict
n, m = [int(i) for i in input().split(" ")]
ct = 0
#dic = defaultdict(tuple)
'''for a in range(1001):
    b = n - a*a
    if b>=0 and a>=0 and a + b*b == m:
        ct+=1

if n==m:
    ct -= 1
print(ct)
'''
done = []
for a in range(1001):
    b = n - a*a
    if a*a+b == n and a + b*b == m:
        ct+=1
if n==m:
    ct -=1
print(ct)

# -*- coding: utf-8 -*-
"""
Created on Wed Feb 26 18:48:38 2020

@author: Lenovo
"""

#https://codeforces.com/problemset/problem/214/A

def pair_equation():
    numbers = input().split()
    numbers = [int(i) for i in numbers]

    minimum = min(numbers[0],numbers[1])

    check = [0,0]
    output = 0
    for i in range(minimum):
        check[0] += 1
        check[1] = 0
        for i in range(minimum):
            if ((check[0])**2 + check[1]) == numbers[0] and (check[0] + (check[1])**2) == numbers[1]:
                output += 1
            check[1] += 1

    if output == 0:
        print(-1)
        return
    else:
        print(output)
        return

pair_equation()

__author__ = 'Esfandiar'
from math import sqrt
n,m = map(int,input().split())
b = res = 0

while n:
    yy=sqrt(n)
    if int(yy) == yy and yy+(b**2) == m:
        res+=1
    b+=1
    n-=1
print(res)

ans = 0
n, m = map(int, input().split())
for i in range(n):
    for j in range(m+1):
        if (i*i+j) == n and (j*j+i)== m :
            ans+=1
print ("%d" % ans)

n,m=map(int,input().split())
cnt=0
for i in range(n):
	if (n-i**2)**2+i==m:
		cnt+=1
print(cnt)

n, m = map(int, input().split())
count = 0
for i in range(1001):
    if n**2 - 2*n*i**2 + i**4 - m + i == 0 and (n - i**2) % 1 == 0:
        count += 1
print(count)

import math
n , m = map(int,input().split())
c = 0
l = []
for i in range(45):
    if i in l:
        continue
    a = i**2 + i
    e = m + n - a
    if e < 0:
        break
    d = 1 + 4*e
    v = (- 1 + math.sqrt(d))/2
    if v - int(v) == 0:
        if ((i**2 + v == m) or (v**2 + i == m)) and ((i**2 + v == n) or (v**2 + i == n)):
            l.append(v)
            c += 1
            continue
print(c)

import math
def main():
    n,m = map(int,input().split())
    c = 0
    for i in range(-n,int(math.sqrt(n) + 1)):
        a = i
        b = n - a*a
        if b*b + a == m:
            c += 1
    print(c)

main()

import math
numbers = input()
string = numbers.split(" ")
n=int(string[0])
m=int(string[1])

def is_perfect(number):
    num = number**0.5
    if num == int(num):
        print("Per")
    else:
        print("No")

lista=[]
listb=[]
i=1;
while(i<=math.sqrt(n)):
    b= n-(i**2)
    lista.append([i,b])
    i+=1
total=0

for i in lista:
    if(((i[1]**2)+i[0])==m):
        total+=1
print(total)

n,m = map(int,input().split())
c=0
for a in range(0,n):
    b1 = n-(a*a)
    b2 = (m-a)**(1/2)
    if b1 == b2:
        c += 1
    else:
        pass
print(c)

def solve(n, m):
    return sum(1 for b in range(n + 1)
                 for a in range(m + 1)
                 if a*a + b == n and b*b == m)

def main():
    n, m = list(map(int, input().split()))
    print(solve(n, m))

main()

#n=int(raw_input())
n,m=map(int,raw_input().split())
res=0
for i in range(0,n):
    b=n-i*i
    if b<0:
        break
    if i+b*b==m:
        res+=1
print res

n,m=[int(i) for i in input().split()]
count=0
for i in range(0,1001):
    for j in range(0,1001):
        if((i*i)+(j)==n and (i)+(j*j)==m and i!=j):
            count=count+1
print(count)

import math
p = input()
nums = p.split(" ")
n = int(nums[0])
m = int(nums[1])
count = 0
for a in range(0,max(n,m)+1):
    b = n - a*a
    if a + b*b == m:
        count = count + 1
print(count)

sum1 = 0
temp = map(int, raw_input().split())
n = temp[0]
m = temp[1]
end = min(n,m)
for i in range(end+1):
	b = n-i*i
	if(b<0):
		continue
	if((i+b*b)==m):
		print i
		sum1+=1
print sum1

n, m = map(int, input().split())
count = 0
for i in range(1001):
    if n**2 - 2*n*i**2 + i**4 - m + i == 0:
        count += 1
print(count)

import math
n,m=map(int,input().split())
a=math.sqrt(n)
a=math.floor(a)
b=math.sqrt(m-a)
if(math.floor(b)==math.ceil(b)):
    print(1)
else:
    print(0)

n,m=map(int,input().split())
count=0
a=0
b=0
while a**2+b!=n or a+b**2!=m:
    a+=1
    count+=1
    if a==32:
        a=0
        b+=1
    if a==31 and b==32:
        print(0)
        break
print(1)

n,m = map(int,input().split())
ans = 0
for a in range(min(n,m)+1):
    b = -(a**2 - n)
    if b ** 2 == m - a:
        ans += 1
print(ans)

n, m = [int(x) for x in input().split()]
count = 0
mn = min(n, m)
for a in range(0, mn):
    for b in range(0, mn):
        if (a * a + b == n) and (a + b * b == m):
            count += 1
print(count)

n,m = list(map(int,input().split()))
cc = 0
for a in range(1000):
    for b in range(1000):
        if a*a + b ==n and a + b*b==m or a*a + b ==m and a + b*b==n:
            cc = cc + 1
print(cc//2)

a = map(int,raw_input().split())
d = []
x = 0
while x<1020:
    if  x+ (a[0] - x**2)**2 ==a[1]:
        d.append(x)
    x+=1
print len(d)

n,m = map(int,raw_input().split())
print sum([int(a + (n-a**2)**2 == m) for a in xrange(1,1001)])

#tst problem A
"""
keys = dict()

def chkCond(a,b):
	if a**2+b == int(n) and b**2+a == int(m):
		keys[str(a**2+b) + "|" + str(b**2+a)]=1
		return 1
	return 0

def search(a,b):
	sLeft =0
	sRight=0
	if a**2 + b <= int(n) or b**2+a <= int(m):
		sLeft = search(a+1,b)
		sRight = search(a,b+1)
	return sLeft+sRight+chkCond(a,b)

search(0,0)
"""

I = lambda : map(int, raw_input().split())

def compute(a,n,m):
	l=a*(a*(a**2-2*int(n))+1)+int(n)**2
	if l == int(m):
		return 1
	return 0

def main():
	n, m = I()
	a=1
	ret=0
	while abs(int(n)-a**2) <= 1000:
		ret=ret+compute(a,n,m)
		a=a+1
	print ret# len(keys)

if __name__ == '__main__':
    main()

# coding: utf-8
from math import sqrt

def tim_nghiem(n, so):
    nghiem = sqrt((n - so))
    nghiem_2 = int(nghiem)
    if nghiem == float(nghiem_2):
        return nghiem
    else:
        return None

if __name__ == '__main__':
    n, m = input().split(' ')
    n = int(n)
    m = int(m)
    mang_n = []
    for so_a in range(n):
        if tim_nghiem(n, so_a):
            b = tim_nghiem(n, so_a)
            if tim_nghiem(m, b) is not None:
                a = tim_nghiem(m, b)
                if int(a) == int(so_a):
                    mang_n.append([so_a, b])
    print(len(mang_n))

n,m=map(int,input().split())
k=0
for a in range(1,max(n,m)+1):
    for b in range(1,max(n,m)+1):
        if a**2+b==n and a+b**2==m:
            k+=1
print(k)

s = raw_input

n, m = map(int, s().split())

c = 0
for i in range(max(m, n)):
    for j in range(max(m, n)):
        if i**2+j == n and i+j**2==m:
            c+=1
print c

from math import sqrt
n, m = [int(i) for i in input().split()]
s = n - m
l = []
for i in range(1, abs(s) + 1):
    if s % i == 0:
        l.append(i)
        l.append(-i)
c = 0
for i in l:
    t = i
    k = s // i
    a = (- k - t + 1) / 2
    b = a + t
    if a == int(a) and a*a + b == n and a >= 0 and b >= 0:
        c += 1
print(c)

# -*- coding: utf-8 -*-
"""
Created on Wed Feb 26 18:48:38 2020

@author: Lenovo
"""

#https://codeforces.com/problemset/problem/214/A

def pair_equation():
    numbers = input().split()
    numbers = [int(i) for i in numbers]

    minimum = min(numbers[0],numbers[1])

    check = [0,0]
    output = 0
    for i in range(minimum):
        check[0] += 1
        check[1] = 0
        for i in range(minimum):
            if ((check[0])**2 + check[1]) == numbers[0] and (check[0] + (check[1])**2) == numbers[1]:
                output += 1
            check[1] += 1

    print(output)
    return

pair_equation()

n=list(map(int, input().split()))

print(n)
p=0
for a in range(max(n[0]+1, n[1]+1)):
    for b in range(max(n[0]+1, n[1]+1)):
        if a*a+b==n[0] and b*b+a==n[1]:
            p+=1
            print(a,b)
print(p)

n,m=map(int,raw_input().split(' '))
cnt=0

def f(a,b,n):
     return a**2+b==n
def g(a,b,n):
     return a+b**2==m

for a in xrange(-100,100):
     for b in xrange(-100,100):
          if f(a,b,n) and g(a,b,n):
               cnt+=1
print cnt

# http://codeforces.com/problemset/problem/214/A
n, m  = map(int, input().split())
nm    = max(n,m)
count = 0

for b in range(n):
	for a in range(m):
		sum_a2b = a*a + b
		sum_ab2 = a + b*b

		if ((sum_a2b == n) and (sum_ab2 == m)):
			count += 1

print(count)

#b + n*a = d + m*c
#
#n = (d + m*c - b)/a

import math
def main():
    n,m = map(int,input().split())
    c = 0
    for i in range(-n,int(math.sqrt(n) + 1)):
        a = i
        b = n - a*a
        if b*b + a == m:
            c += 1
    print(c)

main()

lis = list(map(int,input().split()))
lis.sort()
if lis[0]**2 == lis[1]:
    print(1)
elif lis[0]*2==lis[1]:
    print(1)
else:
    print(0)

n, m = map(int, input().split())
a = -1
count = 0
while a * a < n:
    a += 1
    b = 0
    while b * b < m:
        if a*a+b==n and a+b*b == m:
            count +=1
            b += 1
        else:
            b += 1
print(count)

[n,m]=[int(x) for x in input().split()]
a=[]
count=0
for i in range(n+1):
    for j in range(m+1):
        if (i**2)+j==n and i+(j**2)==m:
            count=+1
print(count)

def generator(a,n):
    return a+(n-a**2)**2
s=input()
c=s.split()
n=int(c[0])
m=int(c[1])
a=1
contador=0
for a in range(500,0,-1):
    if(generator(a,n)==m):
        contador+=1
print(contador)

import math
n,m=map(int,input().split())
a=math.sqrt(n)
a=math.floor(a)
b=math.sqrt(m-a)
if(math.floor(b)==math.ceil(b)):
    print(1)
else:
    print(0)

n, m = map(int, input().split())

count = 0
for a in range(max(n, m)):
    for b in range(max(n, m)):
        if a ** 2 + b == n and a + b ** 2 == m:
            count += 1

print(count)

n, m = map(int, input().split())
o = 0
a = 0
b = 0
ia = -1
ib = -1
if n==1 and m==1:
    print(2)
else:
    while a ** 2 <= n:
        a += 1
        ia += 1
    while b ** 2 <= m:
        b += 1
        ib += 1
    if n > m:
        while ia > 0:
            if n - (ia ** 2) <= ib:
                o += 1
                ia -= 1
            else:
                ia -= 1
        print(o)
    else:
        while ib > 0:
            if m - (ib ** 2) <= ia:
                o += 1
                ib -= 1
            else:
                ib -= 1
        print(o)

n,m=list(map(int, input().split(' ')))
k = 0
b = 0
for i in range(1000):
    b = n-i**2
    if i+b**2 == m:
        k+=1
print(k)