Unfortunately for Max, Mr. Gugoiu has caught him playing games during class! Somehow, Annie did not get caught—quite unfair, if you ask me.
As a result, Mr. Gugoiu has given Max a proposition. If Max can solve his challenge (which he got from Ms. Gugoiu), Max will be spared. If he cannot, he will be given an extra physics assignment to complete. The challenge is as follows:
- Given two positive integers, and ,
- You must find the number of positive integer pairs, , such that and .
- For each pair, you must then construct two right triangles: one with shorter sides and , the other with shorter sides and .
- The difference between the squares of the longest side of each triangle must be a prime number.
He gives Max two integers and (the sample input), but Max quickly solves it. Slightly impressed, Mr. Gugoiu decides to give Max such cases. Can you help Max solve them all? Specifically, for every case, find the number of pairs that satisfy the conditions.
Constraints
Subtask 1 [50%]
Subtask 2 [50%]
Input Specification
The first line of input will contain the integer .
The next lines each contain two integers, and .
Output Specification
Output lines, the -th line containing the answer to the -th case.
Sample Input
1
10 15
Sample Output
2
Sample Explanation
The two cases are and .
The two triangles created with have side lengths , and . Taking the difference of the squares of the longest sides yields , which is a prime number.
The two triangles created with have side lengths , and . Taking the difference of the squares of the longest sides yields , which is a prime number.
Comments