Skip to content

Commit 12f6911

Browse files
authored
Merge pull request #105 from hardik-rana02/hardik
2 parents 8fe0997 + 77f6e81 commit 12f6911

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
#define ll long long
5+
#define pb push_back
6+
#define f(i,a,b) for(ll i=a;i<b;i++)
7+
#define fb(i,a,b) for(ll i=a;i>=b;i--)
8+
#define vi vector<int>
9+
#define vl vector<ll>
10+
#define pii pair<int,int>
11+
#define pll pair<ll,ll>
12+
#define vpii vector<pii>
13+
#define vpll vector<pll>
14+
#define all(x) (x).begin(), (x).end()
15+
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
16+
17+
const ll MOD = 1e9+7;
18+
const ll INF = 1e18;
19+
/*
20+
We need to count the no of pairs such that their product makes some number's k-th power-this means the product of the two numbers should have
21+
factors frequency that is divisible by k. For every number first factorize it using spf(also store its factors mod k) and also store how much
22+
factor more it needs to make the k-th power add this for all numbers.
23+
24+
*/
25+
26+
/* Submission Link: https://codeforces.com/contest/1225/submission/355183203 */
27+
void solve() {
28+
int n,k;
29+
cin>>n>>k;
30+
vi a(n);
31+
f(i,0,n) cin>>a[i];
32+
vi spf(1e5+1);
33+
f(i,1,1e5+1) spf[i]=i;
34+
for(int i=2;i*i<=1e5;i++){
35+
if(spf[i]==i){
36+
for(int j=i*i;j<=1e5;j+=i){
37+
if(spf[j]==j){
38+
spf[j]=i;
39+
}
40+
}
41+
}
42+
}
43+
map<vpii,ll> cnt;
44+
ll ans=0;
45+
for(int x:a){
46+
map<int,int> factors;
47+
while(x>1){
48+
int p=spf[x];
49+
int c=0;
50+
while(x%p==0){
51+
x/=p;
52+
c++;
53+
}
54+
c%=k;
55+
if(c>0)
56+
factors[p]=c;
57+
}
58+
vpii key,need;
59+
for(auto &it:factors){
60+
key.pb(it);
61+
int y=(k-it.second)%k;
62+
if(y>0){
63+
need.pb({it.first,y});
64+
}
65+
}
66+
ans+=cnt[need];
67+
cnt[key]++;
68+
}
69+
cout<<ans<<endl;
70+
}
71+
72+
int main() {
73+
fast_io;
74+
int t = 1;
75+
//cin >> t;
76+
while(t--) solve();
77+
return 0;
78+
}

0 commit comments

Comments
 (0)