File tree Expand file tree Collapse file tree
Problems/Mathematics/Day-01/sol/Aaryan_Degama Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ // link : https://codeforces.com/problemset/submission/1225/355484586
2+
3+ #include < bits/stdc++.h>
4+ using namespace std ;
5+
6+ void solve () {
7+ int n, k;
8+ if (!(cin >> n >> k)) return ;
9+
10+ vector<int > a (n);
11+ for (int &x : a) cin >> x;
12+
13+ map<vector<pair<int , int >>, long long > mp;
14+ long long res = 0 ;
15+
16+ for (int x : a) {
17+ int t = x;
18+ vector<pair<int , int >> current_factors, required_factors;
19+
20+ for (int p = 2 ; p * p <= t; p++) {
21+ if (t % p == 0 ) {
22+ int count = 0 ;
23+ while (t % p == 0 ) {
24+ t /= p;
25+ count++;
26+ }
27+ count %= k;
28+ if (count > 0 ) {
29+ current_factors.push_back ({p, count});
30+ required_factors.push_back ({p, k - count});
31+ }
32+ }
33+ }
34+
35+ if (t > 1 ) {
36+ int count = 1 % k;
37+ if (count > 0 ) {
38+ current_factors.push_back ({t, count});
39+ required_factors.push_back ({t, k - count});
40+ }
41+ }
42+
43+ if (mp.count (required_factors)) {
44+ res += mp[required_factors];
45+ }
46+
47+ mp[current_factors]++;
48+ }
49+
50+ cout << res << endl;
51+ }
52+
53+ int main () {
54+ ios::sync_with_stdio (false );
55+ cin.tie (nullptr );
56+
57+ solve ();
58+
59+ return 0 ;
60+ }
You can’t perform that action at this time.
0 commit comments