Răspuns:
#include <iostream>
using namespace std;
int factor(int num)
{
int r=num;
for (int d = 3; d*d <= num; d += 2)
if (num%d == 0)
{
r=d; break;
}
return r;
}
int main()
{
int n, i;
long long s=0, num;
cin >> n;
for (i=1; i<=n; i++)
{
cin >> num;
if (num%2==0) s+=2;
else
{
s=s+factor(num);
}
}
cout << s;
return 0;
}
Explicație: