using
System;
using
System.Linq;
using
System.Collections;
using
System.Collections.Generic;
sealed
class
ListComparer : EqualityComparer<List<
int
[]> > {
public
override
bool
Equals(List<
int
[]> x,
List<
int
[]> y)
{
if
(x.Count != y.Count)
return
false
;
for
(
int
i = 0; i < x.Count; i++) {
if
((x[i][0] != y[i][0])
|| (x[i][1] != y[i][1]))
return
false
;
}
return
true
;
}
public
override
int
GetHashCode(List<
int
[]> x)
{
int
hc = x.Count;
foreach
(
int
[] val
in
x)
{
hc =
unchecked
(hc * 314159 + (val[0] + val[1]));
}
return
hc;
}
}
class
GFG {
static
int
MAXN = 100005;
static
List<
int
> spf =
new
List<
int
>();
static
void
sieve()
{
int
i, j;
spf.Clear();
spf.Add(0);
for
(i = 1; i <= MAXN; i++)
spf.Add(i);
for
(i = 2; i < MAXN; i++) {
if
(spf[i] == i) {
for
(j = i * 2; j < MAXN; j += i) {
if
(spf[j] == j)
spf[j] = i;
}
}
}
}
static
List<
int
[]> getFact(
int
x)
{
List<
int
[]> factors =
new
List<
int
[]>();
while
(x != 1) {
int
z = spf[x];
int
cnt = 0;
while
(x % z == 0) {
cnt++;
x = (
int
)(x / z);
}
factors.Add(
new
[] { z, cnt });
}
return
factors;
}
static
int
pairsWithKth(
int
[] a,
int
n,
int
k)
{
sieve();
int
answer = 0;
Dictionary<List<
int
[]>,
int
> count_of_L
=
new
Dictionary<List<
int
[]>,
int
>(
new
ListComparer());
for
(
var
i = 0; i < n; i++) {
var
factors = getFact(a[i]);
factors = factors.OrderBy(a1 => a1[0])
.ThenBy(a1 => a1[1])
.ToList();
List<
int
[]> L =
new
List<
int
[]>();
foreach
(
var
it
in
factors)
{
if
(it[1] % k == 0)
continue
;
L.Add(
new
[] { it[0], it[1] % k });
}
List<
int
[]> Lx =
new
List<
int
[]>();
foreach
(
var
it
in
L)
{
Lx.Add(
new
[] { it[0], (k - it[1] + k) % k });
}
if
(!count_of_L.ContainsKey(Lx))
count_of_L[Lx] = 0;
else
answer += count_of_L[Lx];
if
(!count_of_L.ContainsKey(L))
count_of_L[L] = 1;
else
count_of_L[L]++;
}
return
answer;
}
public
static
void
Main(
string
[] args)
{
int
n = 6;
int
[] a = { 1, 3, 9, 8, 24, 1 };
int
k = 3;
Console.WriteLine(pairsWithKth(a, n, k));
}
}