给定n个整数和一个k,求有多少个数对(i,j)满足
\[a_i \times a_j = x^k \]我们不妨对每个a进行质因数分解,发现两个数字相乘是某个数的k次方,就是两个数质因数分解后,对应质数的次幂和为k的倍数,这样我们可以hash统计来解决(用map)
#include<bits/stdc++.h>
#define rep(i,j,k) for(int i(j);i<=k;++i)
#define drp(i,j,k) for(int i(j);i>=k;--i)
#define repg(x) for(int i(G.head[x]);i;i=G.next[i])
#define bug cout<<"~~~~~~~~~~~~~"<<'\n';
using std::cin;
using std::cout;
typedef long long lxl;
template<typename T>
inline T max( T a, T b) {
return a > b ? a : b;
}
template<typename T>
inline T min( T a, T b) {
return a < b ? a : b;
}
inline char gt() {
static char buf[1 << 21], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++;
}
template <typename T>
inline void read(T &x) {
char ch = gt();
x = 0;
int w(0);
while(!(ch >= '0' && ch <= '9'))w |= ch == '-', ch = gt();
while(ch >= '0' && ch <= '9')x = x * 10 + (ch & 15), ch = gt();
w ? x = ~(x - 1) : x;
}
template <typename T>
inline void out(T x, char cc) {
if(x < 0) x = -x, putchar('-');
char ch[20];
int num(0);
while(x || !num) ch[++num] = x % 10 + '0', x /= 10;
while(num) putchar(ch[num--]);
putchar(cc);
}
const int N = 1e5 + 79;
int n, a, k;
std::vector<std::pair<int, int> > x, y;
std::map<std::vector<std::pair<int, int> >, int> mp;
lxl ans;
int prime[N], tot, v[N];
inline void EulerSieve(int MX) {
rep(i, 2, MX) {
if(!v[i]) {
v[i] = i;
prime[++tot] = i;
}
rep(j, 1, tot) {
if(prime[j] > v[i] || 1ll * i * prime[j] > MX) break;
v[i * prime[j]] = prime[j];
}
}
}
int main() {
EulerSieve(100000);
read(n);
read(k);
while(n--) {
read(a);
x.clear();
y.clear();
rep(i, 1, tot) {
if(prime[i]*prime[i] > a) break;
int cnt(0);
while(a % prime[i] == 0) {
++cnt;
a /= prime[i];
cnt %= k;
}
if(!cnt) continue;
x.push_back({prime[i], cnt});
y.push_back({prime[i], k - cnt});
}
if(a != 1) { //±¾ÉíÊÇÒ»¸öÖÊÊý
x.push_back({a, 1});
y.push_back({a, k - 1});
}
ans += mp[y];
++mp[x];
}
out(ans, '\n');
return 0;
}