From LỚP 9_1
About
include <bits/stdc++.h>
define ll long long
define fr(i,a,b) for(int i = a; i <= b; i++)
define phat ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std; ll n,a[1000000+3],f[10000000+3]; void doc() { cin>>n; fr(i,1,n) cin>>a[i]; } void sangnt() { int M = 1e7; fr(i,1,M) f[i] = 1; f[1] = 0; fr(i,2,sqrt(M)){ if(f[i] == 1){ for(int j = i * i; j <= M; j += i) f[j] = 0; } } } int main(){ phat; doc(); sangnt(); fr(i,1,n){ if(f[a[i]]) cout<<a[i]<<" "; } return 0; }