Tprime code doubt

giving wrong answer for 2 test cases

@rohit_1906
If the number is perfectSquare, it doesn’t mean that it is T-prime (has only 3 divisor). Consider 36 which is perfectSquare ( 6*6) but it is not a T-prime since have 1,2,3,6,12,18,36 as divisors. Your code is printing “YES” but ans is “NO”

for integer x if perfectSquare(x) is true, check whether its sqrt(x) is prime or not. if prime, ans is “YES” else “NO”

hey there I am facing the same problem even I have tested for perfect square and if the root of it is prime or not
I have attached my code below please can you help me with the same
#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;
    }
}

}