Răspuns :
#include <iostream>
using namespace std;
int main()
{
int n, i, d, nrd;
cin >> n;
int v[n];
for (i=1; i<=n; i++)
{
cin >> v[i];
nrd=0;
if (v[i]%2==0) v[i]=2;
else
{
for (d=1; d<=v[i]/2; d++)
if (v[i]%d==0) nrd++;
if (nrd==1) v[i]=1;
else v[i]=3;
}
}
for (i=1; i<=n; i++) cout << v[i] << " ";
return 0;
}
Răspuns:
#include <iostream>
using namespace std;
int main()
{
int n, i, d, nrd;
cin >> n;
int v[n];
for (i=1; i<=n; i++)
{
cin >> v[i];
nrd=0;
if (v[i]%2==0) v[i]=2;
else
{
for (d=1; d<=v[i]/2; d++)
if (v[i]%d==0) nrd++;
if (nrd==1) v[i]=1;
else v[i]=3;
}
}
for (i=1; i<=n; i++) cout << v[i] << " ";
return 0;
}
Explicație: