CF567C.Geometric Progression

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer k and a sequence a, consisting of n integers.

He wants to know how many subsequences of length three can be selected from a, so that they form a geometric progression with common ratio k.

A subsequence of length three is a combination of three such indexes _i_1, _i_2, _i_3, that 1 ≤ _i_1 < _i_2 < _i_3 ≤ n. That is, a subsequence of length three are such groups of three elements that are not necessarily consecutive in the sequence, but their indexes are strictly increasing.

A geometric progression with common ratio k is a sequence of numbers of the form b·_k_0, b·_k_1, ..., b·k__r - 1.

Polycarp is only three years old, so he can not calculate this number himself. Help him to do it.

波利卡普非常喜爱等比数列。自他三岁起,他就只喜欢长度为三的等比数列。此外,他还有一个最喜爱的整数 kk 和一个由 nn 个整数组成的序列 aa。

他想知道:从 aa 中可以选出多少个长度为三的子序列,使其构成公比为 kk 的等比数列。

长度为三的子序列是指满足 1≤i1<i2<i3≤n1 \le i_1 < i_2 < i_3 \le n 的三个下标 i1, i2, i3i_1,\,i_2,\,i_3 所对应的元素组合。也就是说,长度为三的子序列是由序列中三个元素组成的集合,这些元素在原序列中未必连续,但其下标严格递增。

公比为 kk 的等比数列是一组形如 b⋅k0, b⋅k1, …, b⋅kr−1b\cdot k^0,\,b\cdot k^1,\,\dots,\,b\cdot k^{r-1} 的数列。

波利卡普只有三岁,因此他自己无法计算这个数目。请帮助他完成计算。

输入格式

The first line of the input contains two integers, n and k (1 ≤ n, k ≤ 2·105), showing how many numbers Polycarp's sequence has and his favorite number.

The second line contains n integers _a_1, _a_2, ..., a__n ( - 109 ≤ a__i ≤ 109) — elements of the sequence.

输入的第一行包含两个整数 nn 和 kk(1≤n,k≤2⋅1051 \leq n, k \leq 2 \cdot 10^5),分别表示 Polycarp 序列中数字的个数以及他的幸运数字。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(−109≤ai≤109-10^9 \leq a_i \leq 10^9)——序列的元素。

输出格式

Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio k.

输出一个整数——选择长度为三的子序列的方案数,使得该子序列构成公比为 kk 的等比数列。

输入输出样例

  • 输入#1

    5 2
    1 1 2 2 4

    输出#1

    4
  • 输入#2

    3 1
    1 1 1

    输出#2

    1
  • 输入#3

    10 3
    1 2 6 2 3 6 9 18 3 9

    输出#3

    6

说明/提示

In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4.

在第一个样例测试中,答案为四:任意一个 11 都可被选作子序列的第一个元素,第二个元素可以是任意一个 22,而子序列的第三个元素必须等于 44。

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

首页