Skip to content

Commit f2a9a9f

Browse files
committed
Solution2 Day 1
1 parent 60face7 commit f2a9a9f

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
const int MAXA = 100000;
5+
int spf[MAXA + 1];
6+
7+
int main()
8+
{
9+
ios::sync_with_stdio(false);
10+
cin.tie(NULL);
11+
12+
for (int i = 1; i <= MAXA; i++)
13+
spf[i] = i;
14+
for (int i = 2; i * i <= MAXA; i++)
15+
{
16+
if (spf[i] == i)
17+
{
18+
for (int j = i * i; j <= MAXA; j += i)
19+
{
20+
if (spf[j] == j)
21+
spf[j] = i;
22+
}
23+
}
24+
}
25+
26+
int n, k;
27+
cin >> n >> k;
28+
29+
map<vector<pair<int, int>>, long long> freq;
30+
long long ans = 0;
31+
32+
for (int i = 0; i < n; i++)
33+
{
34+
int x;
35+
cin >> x;
36+
37+
map<int, int> cnt;
38+
while (x > 1)
39+
{
40+
cnt[spf[x]]++;
41+
x /= spf[x];
42+
}
43+
44+
vector<pair<int, int>> cur, need;
45+
46+
for (auto &pr : cnt)
47+
{
48+
int p = pr.first;
49+
int r = pr.second % k;
50+
if (r > 0)
51+
{
52+
cur.push_back({p, r});
53+
need.push_back({p, (k - r) % k});
54+
}
55+
}
56+
57+
sort(cur.begin(), cur.end());
58+
sort(need.begin(), need.end());
59+
60+
ans += freq[need];
61+
freq[cur]++;
62+
}
63+
64+
cout << ans << "\n";
65+
return 0;
66+
}

0 commit comments

Comments
 (0)