Chang's new maths teacher is very enthusiastic about making sure that students understand the concept rather than remembering it. On her first day at teaching, she gives an assignment to all the students to test their potential. Chang wants to demonstrate that he understands the concept rather than rote learning. Help Chang in doing this by solving the hardest problem in the assignment. The problem is written as follows. 

A perfect function is defined in the following manner.

- F(x, y) = x2 + y for 1 ≤ x ≤ A, 1 ≤ y ≤ B
- F(x, y) = 2 otherwise

Find the number of integral pairs (x, y) such that F(x, y) is a perfect square.

-----Input-----
First and the only line of the input contains two single space separated integers A and B.

-----Output-----
Output a single integer indicating the output to the only test case.

-----Constraints-----
- 1 ≤ A, B ≤ 106

-----Example-----
Input:
4 4

Output:
1

-----Explanation-----
Example case 1.
(1, 3) is the only pair such that x = 1, y = 3 satisfying x <= 4 and y <= 4. 1^2 + 3 = 4 which is a perfect square.

Difficulty: interview

Starter code:

Solutions:
from math import sqrt

a, b = map(int, input().split())
pairs = 0

for i in range(1, a+1):
 for j in range(1, b+1):
  root = sqrt(i**2 + j)

  if not root - int(root):
   pairs += 1

print(pairs)

#just code here
import math 
 
def isPerfectSquare(x): 
 
 # Find floating point value of  
 # square root of x. 
 sr = math.sqrt(x) 
 
 # If square root is an integer 
 return ((sr - math.floor(sr)) == 0) 

a,b=list(map(int,input().split()))
c=0
for i in range(1,a+1):
 for j in range(1,b+1):
  s=(i*i + j)
  if isPerfectSquare(s):
   c+=1 
print(c)
  


# cook your dish here
import math
a,b=list(map(int,  input().split()))
l=[]
for x in range(1,a+1):
 for y in range(1,b+1):
  f=(x**2)+y
  r=math.sqrt(f)
  if int(r+0.5)**2==f:
   l.append(1)
  else:
   l.append(0)
print(sum(l))


A,B=[int(i) for i in input().split()]
counter=0
for x in range(1,A+1):
 num=x**2+B
 counter+=(int(num**0.5)-x)
 #print(x,num)
print(counter)

A,B=[int(i) for i in input().split()]
counter=0
for x in range(1,A+1):
 num=x**2+B
 counter+=(int(num**0.5)-x)
 #print(x,num)
print(counter)

# cook your dish here

x,y=list(map(int,input().split()))
pair=0
for i in range(1,x+1):
 pair+=int(((i**2)+y)**0.5)-i
print(pair)
 


# cook your dish here
import math
a,b=map(int,input().split())
ct=0
for i in range(1,a+1):
 for j in range(1,b+1):
  x=math.sqrt(i*i+j)
  if x-int(x)==0:
   ct=ct+1
print(ct)

# cook your dish here
import math
a, b = list(map(int, input().split()))
c=0
for i in range(1,a+1):
 for j in range(1,b+1):
  n=i**2+j 
  sr=math.sqrt(n)
  if(sr-math.floor(sr)==0):
   c+=1 
print(c) 

# cook your dish here
a,b=map(int,input().split())
f=0
for i in range(1,a+1):
 for j in range(1,b+1):
  c=i*i+j
  d=c**0.5
  e=int(d)
  if(d==e):
   f+=1
print(f)

# cook your dish here
a,b=map(int,input().split())
c=0
for i in range(1,a+1):
 for j in range(1,b+1):
  x=i*i+j
  d=x**0.5
  e=int(d)
  if d==e:
   c+=1
print(c)

a,b=map(int,input().split())
c=0
for i in range(1,a+1):
 for j in range(1,b+1):
  a1=i*i+j
  a2=a1**(0.5)
  a3=int(a2)
  if(a3==a2):
   c+=1
print(c) 

# cook your dish here
a,b=map(int,input().strip().split(' '))
count=0
import math
r=int(math.sqrt(b))
for i in range(1,a+1):
  for j in range(1,b+1):
   r=i*i+j
   x=math.sqrt(r)
   if(int(x)==x):
    count+=1
print(count)

a,b=map(int,input().split())
c=0
for i in range(1,a+1):
 for j in range(1,b+1):
  a1=i*i+j
  a2=a1**(0.5)
  a3=int(a2)
  if(a3==a2):
   c+=1
print(c) 

a,b=str(input()).split(" ")
a=int(a)
b=int(b)
count=0
for i in range(1,a+1):
 for j in range(1,b+1):
  a1=i*i+j
  a2=a1**(0.5)
  a3=int(a2)
  if(a3==a2):
   count+=1
print(count) 

a,b=map(int,input().split())
c=0
for i in range(1,a+1):
 for j in range(1,b+1):
  a1=i*i+j
  a2=a1**(0.5)
  a3=int(a2)
  if(a3==a2):
   c+=1
print(c) 

a,b=str(input()).split(" ")
a=int(a)
b=int(b)
count=0
for i in range(1,a+1):
 for j in range(1,b+1):
  a1=i*i+j
  a2=a1**(0.5)
  a3=int(a2)
  if(a3==a2):
   count+=1
print(count) 

# cook your dish here
import math
a,b=map(int,input().split())
c=0
for i in range(2,int(math.sqrt(a*a+b))+1):
 for x in range(1,i):
  if x>a:
   break
  c+=int(i*i-x*x<=b)
print(c)

# cook your dish here
import math
a,b=map(int,input().split())
c=0
for x in range(1,a+1):
 for y in range(1,b+1):
  if math.modf(math.sqrt(float(x*x)+float(y)))[0]==0.0:
   c+=1
print(c)

import math

p=[int(i) for i in input().split()]

count=0
for i in range(1,p[0]+1):
 k=i+1
 while True:
  y=k*k-i*i
  if y>=1 and y<=p[1]:
   count+=1
  else:
   break
  k=k+1
print(count)

import math

p=[int(i) for i in input().split()]

count=0
for i in range(1,p[0]+1):
 for j in range(1,p[1]+1):
  k=i*i+j
  k1=int(math.sqrt(k))
  if k1*k1==k:
   count+=1
print(count)

# cook your dish here
a,b=map(int,input().split())
ans=0
for x in range(1,a+1):
 m=1
 y=0
 while y<b:
  y=m*(2*x+m)
  if y>b:
   break
  ans+=1
  m+=1
print(ans)

# cook your dish here
import math
a,b=map(int,input().split())
x=1
y=1
res=0
for i in range(1,a+1):
 for j in range(1,b+1):
  temp=i*i+j
  sr=math.sqrt(temp)
  if sr-math.floor(sr)==0:
   res+=1
print(res)

# cook your dish here
#872//2
import math
a,b=list(map(int,input().split()))
l=[]
m=[]
cnt=0
for i in range(1,a+1):
 for j in range(1,b+1):
  y=i**2+j
  m=math.sqrt(y)
  if m==math.floor(m):
   cnt+=1
print(cnt) 
  
 


# cook your dish here
#872//2
import math
a,b=list(map(int,input().split()))
l=[]
m=[]
cnt=0
for i in range(1,a+1):
 for j in range(1,b+1):
  y=i**2+j
  if math.sqrt(y)==math.floor(math.sqrt(y)):
   cnt+=1
print(cnt) 
  
 


# cook your dish here
#872//2
import math
a,b=list(map(int,input().split()))
l=[]
m=[]
for i in range(1,a+1):
 l.append(i*i)
for i in range(1,b+1):
 m.append(i)
cnt=0
for i in range(a):
 for j in range(b):
  y=l[i]+m[j]
  if math.sqrt(y)==math.floor(math.sqrt(y)):
   cnt+=1
print(cnt)