CF1822G1.Magic Triples (Easy Version)

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is the easy version of the problem. The only difference is that in this version, ai≤106a_i \le 10^6.

For a given sequence of nn integers aa, a triple (i,j,k)(i, j, k) is called magic if:

  • 1≤i,j,k≤n1 \le i, j, k \le n.
  • ii, jj, kk are pairwise distinct.
  • there exists a positive integer bb such that ai⋅b=aja_i \cdot b = a_j and aj⋅b=aka_j \cdot b = a_k.

Kolya received a sequence of integers aa as a gift and now wants to count the number of magic triples for it. Help him with this task!

Note that there are no constraints on the order of integers ii, jj and kk.

这是该问题的简单版本。唯一的区别在于,在此版本中,ai≤106a_i \le 10^6。

对于给定的 nn 个整数构成的序列 aa,三元组 (i,j,k)(i, j, k) 被称为魔法三元组,当且仅当满足以下条件:

  • 1≤i,j,k≤n1 \le i, j, k \le n;
  • ii、jj、kk 两两互不相同;
  • 存在某个正整数 bb,使得 ai⋅b=aja_i \cdot b = a_j 且 aj⋅b=aka_j \cdot b = a_k。

Kolya 收到了一个整数序列 aa 作为礼物,现在他想统计其中魔法三元组的个数。请帮助他完成这项任务!

注意:对下标 ii、jj、kk 的大小顺序没有任何限制。

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. The description of the test cases follows.

The first line of the test case contains a single integer nn (3≤n≤2⋅1053 \le n \le 2 \cdot 10^5) — the length of the sequence.

The second line of the test contains nn integers a1,a2,a3,…,ana_1, a_2, a_3, \dots, a_n (1≤ai≤1061 \le a_i \le 10^6) — the elements of the sequence aa.

The sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(3≤n≤2⋅1053 \le n \le 2 \cdot 10^5)—— 表示序列的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,a3,…,ana_1, a_2, a_3, \dots, a_n(1≤ai≤1061 \le a_i \le 10^6)—— 表示序列 aa 的元素。

所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output a single integer — the number of magic triples for the sequence aa.

对于每个测试用例,输出一个整数——序列 aa 中魔法三元组的个数。

输入输出样例

  • 输入#1

    7
    5
    1 7 7 2 7
    3
    6 2 18
    9
    1 2 3 4 5 6 7 8 9
    4
    1000 993 986 179
    7
    1 10 100 1000 10000 100000 1000000
    8
    1 1 2 2 4 4 8 8
    9
    1 1 1 2 2 2 4 4 4

    输出#1

    6
    1
    3
    0
    9
    16
    45

说明/提示

In the first example, there are 66 magic triples for the sequence aa — (2,3,5)(2, 3, 5), (2,5,3)(2, 5, 3), (3,2,5)(3, 2, 5), (3,5,2)(3, 5, 2), (5,2,3)(5, 2, 3), (5,3,2)(5, 3, 2).

In the second example, there is a single magic triple for the sequence aa — (2,1,3)(2, 1, 3).

在第一个例子中,序列 aa 有 66 个魔法三元组:(2,3,5)(2, 3, 5)、(2,5,3)(2, 5, 3)、(3,2,5)(3, 2, 5)、(3,5,2)(3, 5, 2)、(5,2,3)(5, 2, 3)、(5,3,2)(5, 3, 2)。

在第二个例子中,序列 aa 有唯一一个魔法三元组:(2,1,3)(2, 1, 3)。

输入解题思路,AI测评打分。不知道怎么写?

首页