---
category_name: easy
problem_code: CHNGFUNC
problem_name: 'Chang and the Perfect Function'
languages_supported:
- ADA
- ASM
- BASH
- BF
- C
- 'C99 strict'
- CAML
- CLOJ
- CLPS
- 'CPP 4.3.2'
- 'CPP 6.3'
- CPP14
- CS2
- D
- ERL
- FORT
- FS
- GO
- HASK
- ICK
- ICON
- JAVA
- JS
- 'LISP clisp'
- 'LISP sbcl'
- LUA
- NEM
- NICE
- NODEJS
- 'PAS fpc'
- 'PAS gpc'
- PERL
- PERL6
- PHP
- PIKE
- PRLG
- PYPY
- PYTH
- 'PYTH 3.5'
- RUBY
- SCALA
- 'SCM chicken'
- 'SCM guile'
- 'SCM qobi'
- ST
- TCL
- TEXT
- WSPC
max_timelimit: '1'
source_sizelimit: '50000'
problem_author: prateekg603
problem_tester: null
date_added: 25-06-2017
tags:
- cook84
- easy
- maths
- number
- prateekg603
editorial_url: 'https://discuss.codechef.com/problems/CHNGFUNC'
time:
view_start_date: 1500834600
submit_start_date: 1500834600
visible_start_date: 1500834600
end_date: 1735669800
current: 1514815999
layout: problem
---
All submissions for this problem are available.### Read problems statements in [mandarin chinese](http://www.codechef.com/download/translated/COOK84/mandarin/CHNGFUNC.pdf), [russian](http://www.codechef.com/download/translated/COOK84/russian/CHNGFUNC.pdf) and [vietnamese](http://www.codechef.com/download/translated/COOK84/vietnamese/CHNGFUNC.pdf) 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) = 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
<pre><b>Input:</b>
4 4
<b>Output:</b>
1
</pre>### Explanation
**Example case 1.**(1, 3) is the only pair such that x = 1, y = 3 satisfying x