using
System;
using
System.Collections.Generic;
namespace
CSharpProgram
{
class
MainClass
{
static
bool
checkDistinctPrime(
int
n)
{
int
original = n;
int
product = 1;
if
(n % 2 == 0)
{
product *= 2;
while
(n % 2 == 0)
{
n /= 2;
}
}
for
(
int
i = 3; i <= Math.Sqrt(n); i += 2)
{
if
(n % i == 0)
{
product = product * i;
while
(n % i == 0)
{
n /= i;
}
}
}
if
(n > 2)
{
product = product * n;
}
return
product == original;
}
static
bool
check(
int
pos, List<
int
> subset,
List<
int
> unique)
{
foreach
(
int
num
in
subset)
{
if
(gcd(num, unique[pos]) != 1)
{
return
false
;
}
}
return
true
;
}
static
int
countPrime(
int
pos, List<
int
> currSubset,
List<
int
> unique, Dictionary<
int
,
int
> frequency)
{
if
(pos == unique.Count)
{
if
(currSubset.Count == 0)
{
return
0;
}
int
count = 1;
foreach
(
int
element
in
currSubset)
{
count *= frequency[element];
}
return
count;
}
int
ans = 0;
if
(check(pos, currSubset, unique))
{
ans += countPrime(pos + 1, currSubset, unique, frequency);
currSubset.Add(unique[pos]);
ans += countPrime(pos + 1, currSubset, unique, frequency);
currSubset.RemoveAt(currSubset.Count - 1);
}
else
{
ans += countPrime(pos + 1, currSubset, unique, frequency);
}
return
ans;
}
static
int
countSubsets(List<
int
> arr,
int
N)
{
HashSet<
int
> uniqueSet =
new
HashSet<
int
>();
foreach
(
int
element
in
arr)
{
if
(checkDistinctPrime(element))
{
uniqueSet.Add(element);
}
}
List<
int
> unique =
new
List<
int
>(uniqueSet);
Dictionary<
int
,
int
> frequency =
new
Dictionary<
int
,
int
>();
foreach
(
int
element
in
unique)
{
frequency.Add(element, arr.FindAll(x => x == element).Count);
}
int
ans = countPrime(0,
new
List<
int
>(), unique, frequency);
return
ans;
}
static
int
gcd(
int
a,
int
b)
{
if
(b == 0)
return
a;
return
gcd(b, a % b);
}
public
static
void
Main(
string
[] args)
{
List<
int
> arr =
new
List<
int
>();
arr.Add(2);
arr.Add(4);
arr.Add(7);
arr.Add(10);
int
N = arr.Count;
int
ans = countSubsets(arr, N);
Console.WriteLine(ans);
}
}
}