using
System;
using
System.Collections.Generic;
class
GFG
{
static
int
MAXN = 1000001;
static
int
[]spf =
new
int
[MAXN];
static
void
sieve()
{
spf[1] = 1;
for
(
int
i = 2; i < MAXN; i++)
spf[i] = i;
for
(
int
i = 4; i < MAXN; i += 2)
spf[i] = 2;
for
(
int
i = 3; i * i < MAXN; i++)
{
if
(spf[i] == i)
{
for
(
int
j = i * i; j < MAXN; j += i)
if
(spf[j] == j)
spf[j] = i;
}
}
}
static
int
sumFactors(
int
[]arr,
int
n)
{
sieve();
Dictionary<
int
,
int
> map =
new
Dictionary<
int
,
int
>();
for
(
int
i = 0 ; i < MAXN ; ++i)
map.Add(i, 0);
for
(
int
i = 0; i < n; ++i)
{
if
(map.ContainsKey(arr[i]))
{
map[arr[i]] = 1;
}
else
{
map.Add(arr[i], 1);
}
}
int
sum = 0;
for
(
int
i = 0; i < n; ++i)
{
int
num = arr[i];
while
(num != 1 &&
(
int
)(map[spf[num]]) == 1)
{
num /= spf[num];
}
if
(num == 1)
sum += arr[i];
}
return
sum;
}
public
static
void
Main(String []args)
{
int
[]arr = { 5, 11, 55, 25, 100 };
int
n = arr.Length;
Console.WriteLine(sumFactors(arr, n));
}
}