Skip to content

Commit 23c2a0b

Browse files
Create solution002.py
1 parent b861dab commit 23c2a0b

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int main() {
5+
int n, k;
6+
cin >> n >> k;
7+
8+
vector<int> a(n);
9+
for (int i = 0; i < n; i++)
10+
cin >> a[i];
11+
12+
map<vector<pair<int,int>>, long long> freq;
13+
long long ans = 0;
14+
15+
for (int i = 0; i < n; i++) {
16+
int x = a[i];
17+
vector<pair<int,int>> cur, need;
18+
19+
for (int p = 2; p * p <= x; p++) {
20+
if (x % p == 0) {
21+
int cnt = 0;
22+
while (x % p == 0) {
23+
x /= p;
24+
cnt++;
25+
}
26+
cnt %= k;
27+
if (cnt > 0) {
28+
cur.push_back({p, cnt});
29+
need.push_back({p, (k - cnt) % k});
30+
}
31+
}
32+
}
33+
34+
if (x > 1) {
35+
cur.push_back({x, 1});
36+
need.push_back({x, (k - 1) % k});
37+
}
38+
sort(cur.begin(), cur.end());
39+
sort(need.begin(), need.end());
40+
41+
ans += freq[need];
42+
freq[cur]++;
43+
}
44+
cout << ans << "\n";
45+
return 0;
46+
}

0 commit comments

Comments
 (0)