Making a Square
InterviewTime limit2sMemory limit512 MB
Given n distinct positive integers, count ordered pairs (i, j) such that a_i^2 + a_j is a perfect square.
- Level
Medium6 of 10
- Topics
- Math, Number theory, Hash map, Brute force
- Solved
- No attempts yet
Problem
You are given an array of distinct positive integers. Find the number of pairs with for which is a square of an integer.
Input
The first line of the input contains a single integer (), the size of the array.
The second line of the input contains distinct positive integers ().
Output
Output a single integer: the answer to the problem.
Hint
In the example, there are two such pairs, corresponding to and .