qscqesze
Published on 2017-09-02 11:31 in 暂未分类 with qscqesze

# Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2) D. Power Products 数学 暴力

## D. Power Products

You are given n positive integers a1,…,an, and an integer k≥2. Count the number of pairs i,j such that 1≤i<j≤n, and there exists an integer x such that ai⋅aj=xk.

## Input

The first line contains two integers n and k (2≤n≤105, 2≤k≤100).

The second line contains n integers a1,…,an (1≤ai≤105).

## Output

Print a single integer — the number of suitable pairs.

input
6 3
1 3 9 8 24 1
output
5

## Note

In the sample case, the suitable pairs are:

a1⋅a4=8=23;
a1⋅a6=1=13;
a2⋅a3=27=33;
a3⋅a5=216=63;
a4⋅a6=8=23.

## 代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n,k;
int a[maxn];
map<vector<pair<int,int> >,int>H;
int main(){
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
long long ans = 0;
for(int i=0;i<n;i++){
string tmp="";
vector<pair<int,int> >fac;
for(int now=2;now*now<=a[i];now++){
int number=0;
while(a[i]%now==0){
a[i]/=now;
number+=1;
}
if(number%k)
fac.push_back(make_pair(now,number%k));
}
if(a[i]>1)fac.push_back(make_pair(a[i],1%k));
vector<pair<int,int> >fac2;
for(int j=0;j<fac.size();j++){
fac2.push_back(make_pair(fac[j].first,k-fac[j].second));
}
ans+=H[fac2];
H[fac]++;
}
cout<<ans<<endl;
}
posted @ 2019-11-01 00:31  qscqesze  阅读(112)  评论(0编辑  收藏