#d1704. 合适数对(数据加强版)

合适数对(数据加强版)

Nice Pairs (Hard Version)

Problem Description

You are given a sequence a1,a2,…,ana_1, a_2, \dots, a_n of nn positive integers and a positive integer kk. Count how many pairs (l,r)(l, r) satisfy all of the following:

  • 1≤l<r≤n1 \le l < r \le n;
  • there exists an integer xx such that al×ar=xka_l \times a_r = x^k.

Input Format

The first line contains two integers n,kn, k.

The second line contains nn positive integers a1,a2,…,ana_1, a_2, \dots, a_n.

Output Format

One integer: the number of valid pairs.

Sample Input

6 3
1 3 9 8 24 1

Sample Output

5

Constraints

For all test points, 2≤n≤1062 \le n \le 10^6, 2≤k≤1002 \le k \le 100, and 1≤ai≤1071 \le a_i \le 10^7.