[a_i*a_j=x^k\
a_i=prod_{i=1}^np_i^{A_i}~~~b_i=prod_{i=1}^np_i^{B_i}~~~x=prod_{i=1}^np_i^{C_i*k}\
prod_{i=1}^np_i^{A_i+B_i}=prod_{i=1}^np_i^{C_i*k}\
A_i+B_i=k*t~~~~~(A_i+B_i)\%k=0
]
每一个数在质因数分解的时候记录与x相同质因数相加是k的倍数的状态为x1
用map维护每一个状态的合法总数,答案加上mp[x1],把mp[x]+1就好了
map <vector< pair<int,int> > , int > mp;
vector<pair<int,int>> x,x1;
int n,k,a[300005];
long long ans=0;
int main() {
scanf("%d%d",&n,&k);
for (int i=1;i<=n;++i) {
scanf("%d",&a[i]);
x.clear();x1.clear();
int aa=a[i];
for (int j=2;j*j<=a[i];++j) {
int tot=0;
while(aa%j==0) {
++tot;
aa/=j;
tot%=k;
}
if(!tot) continue;
x.push_back({j,tot});
x1.push_back({j,k-tot});
}
if(aa!=1) {
x.push_back({aa,1});
x1.push_back({aa,k-1});
}
ans=ans+mp[x1];
++mp[x];
}
printf("%lld
",ans);
}