#t109. 完全平方数

完全平方数

Perfect Squares

Problem Description

Xiaoyang has a sequence AA of nn non-negative integers. He wants to know how many index pairs ⟨i,j⟩\langle i,j \rangle with 1≤i<j≤n1 \le i < j \le n satisfy that Ai+AjA_i + A_j is a perfect square.

(xx is a perfect square if there exists a non-negative integer yy such that y×y=xy \times y = x.)

This problem has a corresponding multiple-choice / true-or-false question; see https://ti.luogu.com.cn/problemset/1143.

Input Format

The first line is a non-negative integer nn, the number of non-negative integers.

The second line contains nn non-negative integers A1,A2,…,AnA_1, A_2, \dots, A_n, the elements of sequence AA.

Output Format

Output one line containing one integer: the answer.

Sample Input

5
1 4 3 3 5

Sample Output

3

Sample Explanation

For the sample, the sequence is [1,4,3,3,5][1, 4, 3, 3, 5], with 55 numbers in total. The index pairs for which Ai+AjA_i + A_j is a perfect square are:

  • ⟨1,3⟩\langle 1, 3 \rangle: 1+3=4=2×21 + 3 = 4 = 2 \times 2, a perfect square.
  • ⟨1,4⟩\langle 1, 4 \rangle: 1+3=41 + 3 = 4, also a perfect square (note that the sequence contains two 33's at different positions).
  • ⟨2,5⟩\langle 2, 5 \rangle: 4+5=9=3×34 + 5 = 9 = 3 \times 3, a perfect square.

None of the other pairs sum to a perfect square, so the answer is 33.

Constraints

For all test data, 1≤n≤10001 \le n \le 1000 and 0≤Ai≤1050 \le A_i \le 10^5.