Răspuns :
#include <iostream>
#include <math.h>
using namespace std;
int prim(int nr)
{
if (nr < 2)
return 0;
if (nr == 2)
return 1;
if (nr % 2 == 0)
return 0;
for (int d = 3; d * d < nr; d += 2)
if (nr % d == 0)
return 0;
return 1;
}
int nrDivizori(int x)
{
int nr = 0;
for (int d = 1; d <= sqrt(x); d++)
{
if (x % d == 0)
{
if (x / d == d)
nr++;
else nr += 2;
}
}
return nr;
}
bool impare(int x)
{
while (x)
{
if ((x % 10) % 2 == 0)
return false;
x /= 10;
}
return true;
}
int main()
{
int n, nr, vecin;
bool cifre_impare = false;
int sum = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> nr;
if (i == 0)
{
vecin = nr;
cifre_impare = impare(vecin);
}
else
{
if (cifre_impare && prim(nrDivizori(nr)))
{
sum += nr;
}
vecin = nr;
cifre_impare = impare(vecin);
}
}
cout << sum;
return 0;
}