File tree Expand file tree Collapse file tree
Problems/Mathematics/Day-01/sol/Avaneesh Verma Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments