#abc342d. D - Square Pair

D - Square Pair

Score: 400400 points

问题描述

给定一个长度为 NN 的非负整数序列 A=(A1,,AN)A=(A_1,\ldots,A_N)。找出满足以下两个条件的整数对 (i,j)(i,j) 的数量:

  • 1i<jN1\leq i < j\leq N
  • AiAjA_i A_j 是一个完全平方数。

这里,若非负整数 aa 可以表示为某个非负整数 dd 的平方形式,即 a=d2a=d^2,则称 aa 为完全平方数。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a sequence of non-negative integers A=(A1,,AN)A=(A_1,\ldots,A_N) of length NN. Find the number of pairs of integers (i,j)(i,j) that satisfy both of the following conditions:

  • 1i<jN1\leq i < j\leq N
  • AiAjA_i A_j is a square number.

Here, a non-negative integer aa is called a square number when it can be expressed as a=d2a=d^2 using some non-negative integer dd.

Constraints

  • All inputs are integers.
  • 2N2×1052\leq N\leq 2\times 10^5
  • 0Ai2×1050\leq A_i\leq 2\times 10^5

Input

The input is given from Standard Input in the following format:

NN

A1A_1 \ldots ANA_N

Output

Print the answer.

Sample Input 1

5
0 3 2 8 12

Sample Output 1

6

Six pairs of integers, (i,j)=(1,2),(1,3),(1,4),(1,5),(2,5),(3,4)(i,j)=(1,2),(1,3),(1,4),(1,5),(2,5),(3,4), satisfy the conditions.

For example, A2A5=36A_2A_5=36, and 3636 is a square number, so the pair (i,j)=(2,5)(i,j)=(2,5) satisfies the conditions.

Sample Input 2

8
2 2 4 6 3 100 100 25

Sample Output 2

7

update @ 2024/3/10 01:36:20