Chang and the Perfect Function

All submissions for this problem are available.
Read problems statements in mandarin chinese, russian and vietnamese as well.
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) = x^{2} + 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 ≤ 10^{6}
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.
Author:  prateekg603 
Editorial  https://discuss.codechef.com/problems/CHNGFUNC 
Tags  cook84, easymedium, maths, numbertheory, prateekg603 
Date Added:  25062017 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 