#abc249d. D - Index Trio

D - Index Trio

Score : 400400 points

问题描述

给定一个长度为 NN 的整数序列 A=(A1,,AN)A = (A_1, \dots, A_N)

找出满足以下所有条件的整数三元组 (i,j,k)(i, j, k) 的个数。

  • 1i,j,kN1 \leq i, j, k \leq N
  • AiAj=Ak\frac{A_i}{A_j} = A_k

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

Problem Statement

You are given an integer sequence A=(A1,,AN)A = (A_1, \dots, A_N) of length NN.

Find the number of triplets of integers (i,j,k)(i, j, k) satisfying all of the conditions below.

  • 1i,j,kN1 \leq i, j, k \leq N
  • AiAj=Ak\frac{A_i}{A_j} = A_k

Constraints

  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 1Ai2×105(1iN)1 \leq A_i \leq 2 \times 10^5 \, (1 \leq i \leq N)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 \ldots ANA_N

Output

Print the answer.

Sample Input 1

3
6 2 3

Sample Output 1

2

(i,j,k)=(1,2,3),(1,3,2)(i, j, k) = (1, 2, 3), (1, 3, 2) satisfy the conditions.

Sample Input 2

1
2

Sample Output 2

0

Sample Input 3

10
1 3 2 4 6 8 2 2 3 7

Sample Output 3

62

update @ 2024/3/10 10:38:49