using
System;
using
System.Collections.Generic;
class
GFG{
static
readonly
int
N = 10005;
static
void
SieveOfEratosthenes(List<Boolean> composite)
{
for
(
int
i = 0; i < N; i++)
{
composite.Insert(i,
false
);
}
for
(
int
p = 2; p * p < N; p++) {
if
(!composite[p]) {
for
(
int
i = p * 2; i < N; i += p) {
composite.Insert(i,
true
);
}
}
}
}
static
int
sumOfElements(
int
[]arr,
int
n)
{
List<Boolean> composite =
new
List<Boolean>();
for
(
int
i = 0; i < N; i++)
composite.Add(
false
);
SieveOfEratosthenes(composite);
Dictionary<
int
,
int
> mp =
new
Dictionary<
int
,
int
>();
for
(
int
i = 0; i < n; i++)
if
(mp.ContainsKey(arr[i])){
mp[arr[i]] = mp[arr[i]] + 1;
}
else
{
mp.Add(arr[i], 1);
}
int
sum = 0;
foreach
(KeyValuePair<
int
,
int
> it
in
mp){
if
(composite[it.Value]) {
sum += (it.Key);
}
}
return
sum;
}
public
static
void
Main(String[] args)
{
int
[]arr = { 1, 2, 1, 1, 1,
3, 3, 2, 4 };
int
n = arr.Length;
Console.Write(sumOfElements(arr, n));
}
}