Untitled
raw download clone
CPP
views 18
,
size 463 b
#include <fstream>
using namespace std;
ifstream fin("prime.in");
ofstream fout("prime.out");
int prim(int n)
{
    if(n==1 || n==0) 
        return 0;
    if(n!=2 && n%2==0) 
        return 0;
    for(int d=3;d*d<=n;d=d+2)
        if(n%d==0)
            return 0;
    return 1;
}
int main()
{
    int n,x;
    fin>>n;
    for(int i=1;i<=n;i++)
    {
        fin>>x;
        if(prim(x)==1)
            fout<<x<<' ';
    }
    return 0;
}
close fullscreen
Login or Register to edit or fork this paste. It's free.