T-prime number problem

I am trying to solve this quesion of t prime numbers In my practice problems section of my course I am not able to clear two testcases i don’t know how
if you can please help me with this

Problem statement :
We know that prime numbers are positive integers that have exactly two distinct positive divisors. Similarly, we’ll call a positive integer t Т-prime, if t has exactly three distinct positive divisors.

You are given an array of n positive integers. For each of them determine whether it is Т-prime or not.

Input Format

First Line : n , Number of elements in an array Second Line : xi ( i from 1 to n)

Constraints

n <= 10^5 xi <= 10^12

Output Format

YES if its T-Prime NO if its not a T-Prime

Sample Input

3 4 5 6

Sample Output

YES NO NO

Explanation

The first number 4 has exactly three divisors — 1, 2 and 4, thus the answer for this number is “YES”. The second number 5 has two divisors (1 and 5). The third number 6 has four divisors (1, 2, 3, 6), hence the answer for them is “NO”.

code :
#include
#include
#include

using namespace std;

vector primes;
// 0 prime
//1 not prime
void sieve()
{
int n=1000000;
int a[n]={0};
for (int i=2;i<=n;i+=2)
{
a[i]=1;
}
primes.push_back(2);
for(int i=3;i<=n;i+=2)
{
if(a[i]==0)
{
primes.push_back(i);
for(int j=i*i;j<=n;j+=i)
{
a[i]=1;
}
}
}

}

bool primeflag(int n)
{

 for (auto it = primes.begin();it != primes.end(); ++it)
{
    if(n==*it)
       return 1;
}
return 0;

}

bool perfect_square(long long int n)
{
double a= sqrt(n);
int b = sqrt(n);
if (b==a)
{
return 1;
}
else
return 0;

}

int main()
{
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen(“input.txt”, “r”, stdin);
// for writing output to output.txt
freopen(“out.txt”, “w”, stdout);
#endif

sieve();
int t;
cin>>t;
while(t--)
{
   long long int n;
    cin>>n;
    if(perfect_square(n)==1)
    {
        if(primeflag(sqrt(n))==1)
            cout<<"YES"<<endl;
		else 
			cout<<"NO"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
}

}