|
| 1 | +#include <bits/stdc++.h> |
| 2 | + |
| 3 | +#include <ext/pb_ds/assoc_container.hpp> |
| 4 | +#include <ext/pb_ds/tree_policy.hpp> |
| 5 | + |
| 6 | +using namespace std; |
| 7 | +using namespace __gnu_pbds; |
| 8 | + |
| 9 | +typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key |
| 10 | +// less makes it sorted greater makes it reverse sorted less equal makes it like multiset |
| 11 | +// we can also change the data type of the pbds |
| 12 | + |
| 13 | +// Fast I/O |
| 14 | +#define FAST_IO \ |
| 15 | + ios::sync_with_stdio(false); \ |
| 16 | + cin.tie(NULL); |
| 17 | +#define pb push_back |
| 18 | +#define in insert |
| 19 | +#define int long long |
| 20 | +#define all(x) (x).begin(), (x).end() |
| 21 | + |
| 22 | +// Typedefs for convenience |
| 23 | +typedef vector<int> vi; |
| 24 | +typedef pair<int, int> pii; |
| 25 | + |
| 26 | +// Constants |
| 27 | +const int INF = 1e18; |
| 28 | +const int MOD = 1e9 + 7; |
| 29 | + |
| 30 | +// Debug (can be disabled in contests) |
| 31 | +#ifdef DEBUG |
| 32 | +#define dbg(x) cerr << #x << " = " << x << '\n'; |
| 33 | +#else |
| 34 | +#define dbg(x) |
| 35 | +#endif |
| 36 | + |
| 37 | +void solve() |
| 38 | +{ |
| 39 | + int n, k; |
| 40 | + cin >> n >> k; |
| 41 | + vi v(n); |
| 42 | + for (int i = 0; i < n; i++) |
| 43 | + { |
| 44 | + cin >> v[i]; |
| 45 | + } |
| 46 | + vi prime(1e5 + 1); |
| 47 | + map<int, vector<pair<int, int>>> facs; |
| 48 | + |
| 49 | + for (int i = 2; i <= 1e5; i++) |
| 50 | + { |
| 51 | + if (prime[i] == 0) |
| 52 | + { |
| 53 | + for (int j = i; j <= 1e5; j += i) |
| 54 | + { |
| 55 | + if (j != i) |
| 56 | + prime[j] = 1; |
| 57 | + |
| 58 | + int temp = j; |
| 59 | + int cnt = 0; |
| 60 | + while (temp % i == 0) |
| 61 | + { |
| 62 | + temp /= i; |
| 63 | + cnt++; |
| 64 | + } |
| 65 | + |
| 66 | + cnt %= k; |
| 67 | + if (cnt > 0) |
| 68 | + facs[j].pb({i, cnt}); |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + int u = 0; |
| 73 | + int ans = 0; |
| 74 | + map<vector<pair<int, int>>, int> mp; |
| 75 | + for (int i = 0; i < n; i++) |
| 76 | + { |
| 77 | + vector<pair<int, int>> s = facs[v[i]]; |
| 78 | + mp[s]++; |
| 79 | + // if (s.size() == 0) |
| 80 | + // { |
| 81 | + // cout<<v[i]<<" "<<endl; |
| 82 | + // u++; |
| 83 | + // } |
| 84 | + } |
| 85 | + for (auto &p : mp) |
| 86 | + { |
| 87 | + vector<pair<int, int>> s = p.first; |
| 88 | + for (int i = 0; i < s.size(); i++) |
| 89 | + { |
| 90 | + s[i].second = (k - s[i].second); |
| 91 | + } |
| 92 | + if (s != p.first) |
| 93 | + ans += mp[s] * p.second; |
| 94 | + else |
| 95 | + ans += (p.second) * (p.second - 1) / 2; |
| 96 | + p.second = 0; |
| 97 | + } |
| 98 | + |
| 99 | + cout << ans << endl; |
| 100 | +} |
| 101 | + |
| 102 | +signed main() |
| 103 | +{ |
| 104 | + FAST_IO |
| 105 | + int t = 1; |
| 106 | + // cin >> t; |
| 107 | + while (t--) |
| 108 | + solve(); |
| 109 | + return 0; |
| 110 | +} |
| 111 | +/* |
| 112 | + time complexity : 1e5*log1e5 |
| 113 | + space complexity : 1e5 ish |
| 114 | + so basically what I did was I calculated prime factorization of each and every number till 1e5 |
| 115 | + then I took modulo of each exponent with k since while multiplying the sum of exponent of each prime factor must be a multiple of k |
| 116 | +
|
| 117 | + so then I used a map of vector pair to store prime fac of each number |
| 118 | + then I just took into count those numeber which are present in the array using another map |
| 119 | + now in the end I just itereated the map and counted good pairs |
| 120 | +
|
| 121 | +
|
| 122 | + subbmission: |
| 123 | + https://codeforces.com/contest/1225/submission/355181685 |
| 124 | +
|
| 125 | +*/ |
0 commit comments