Untitled
raw download clone
TEXT
views 14
,
size 731 b
#include <iostream>
using namespace std;
void citire(int &n,int v[])
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>v[i];
}
void afisare(int n,int v[])
{
    for(int i=0;i<n;i++)
        cout<<v[i]<<" ";
}
int prim(int n)
{
    if(n<2)
        return 0;
    if(n>2 && n%2==0)
        return 0;
    for(int d=3;d*d<=n;d++)
        if(n%d==0)
        return 0;
    return 1;
}
int urmatorul_prim(int n)
{
    n++;
    while(!prim(n))
        n++;
    return n;
}
void inloc(int n, int v[])
{
    for(int i=0;i<n;i++)
        if(!prim(v[i]))
            v[i]=urmatorul_prim(v[i]);
}
int main()
{
    int n,v[1005];
    citire(n,v);
    inloc(n,v);
    afisare(n,v);
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.