Răspuns :
#Include <iostream>
using namespace std;
bool prim(int n)
{
if(n < 2)
return 0;
if(n > 2 && n % 2 == 0)
return 0;
for(int d = 3; d * d <= n; d += 2)
if(n % d == 0)
return 0;
return 1;
}
int main()
{
int n, v[1001], Min = 2000000001;
cin >> n;
for(int i = 1; i <= n; i ++)
cin >> v[i];
for(int i = 1; i <= n ; i ++)
if(prim(v[i]))
if(v[i] < Min)
Min = v[i];
cout << Min;
return 0;
}
Program C++
#include <iostream>
#include <cmath>
using namespace std;
int main(){
int n, curent, minim=0;
//Citire n
cin >> n;
//Citire numere
for(int i=1;i<=n;i++){
cin >> curent;
//Verifica daca numarul e prim
bool prim=1;
if(curent<2) prim=0;
else {
for(int div=2;div<=sqrt(curent);div++)
if(curent%div==0) prim=0;
}
//Daca numarul e prim si e mai mic decat minimul anterior memoreaza-l
if(prim){
if(!minim)minim=curent;
else if(curent<minim) minim=curent;
}
}
//Afisare numar prim minim (sau mesajul nu exista)
if(minim)cout << minim;
else cout << "Nu exista";
}