1+ /*
2+ DAY 1
3+ Q2 Power Products
4+ .*/
5+
6+ #include < bits/stdc++.h>
7+ using namespace std ;
8+
9+ // Function to factorize a number and return prime exponents modulo k
10+ map<int , int > factorizeMod (long long x, int k) {
11+ map<int , int > factors;
12+ for (long long p = 2 ; p * p <= x; ++p) {
13+ int count = 0 ;
14+ while (x % p == 0 ) {
15+ x /= p;
16+ count++;
17+ }
18+ if (count % k != 0 ) {
19+ factors[p] = count % k; // only store modulo k
20+ }
21+ }
22+ if (x > 1 ) factors[x] = 1 % k; // remaining prime factor
23+ return factors;
24+ }
25+
26+ // Function to compute the complement signature modulo k
27+ map<int , int > complementSignature (const map<int , int >& sig, int k) {
28+ map<int , int > comp;
29+ for (auto &[prime, exp] : sig) {
30+ comp[prime] = (k - exp) % k;
31+ }
32+ return comp;
33+ }
34+
35+ int main () {
36+
37+ int n, k;
38+ cin >> n >> k;
39+ vector<long long > a (n);
40+ for (int i = 0 ; i < n; ++i) cin >> a[i];
41+
42+ // Map to count how many times each signature has occurred
43+ map<map<int ,int >, long long > signatureCount;
44+ long long totalPairs = 0 ;
45+
46+ for (int i = 0 ; i < n; ++i) {
47+ map<int ,int > sig = factorizeMod (a[i], k);
48+ map<int ,int > comp = complementSignature (sig, k);
49+
50+ // Add pairs that match the complement
51+ totalPairs += signatureCount[comp];
52+
53+ // Increment count of current signature
54+ signatureCount[sig]++;
55+ }
56+
57+ cout << totalPairs << " \n " ;
58+ return 0 ;
59+ }
60+
61+
62+ /*
63+ My submission : https://codeforces.com/contest/1225/submission/355325134
64+ */
0 commit comments