T prime not running all test case

public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
//System.out.println(“Size”);
int n=sc.nextInt();
int sqrt;

    //boolean tprime=true;
    int num[]=new int[n];
    int bool[]=new int[n];
    for(int i=0;i<num.length;i++)
    {
        num[i]=sc.nextInt();
    }
    int range=(int)Math.sqrt(num[n-1]);
    for(int i=0;i<num.length;i++)
    {
        sqrt=(int)Math.sqrt(num[i]);
        if(num[i]==sqrt*sqrt)
            bool[i]=1;
    }
    for(int i=2;i<range;i++)
    {
        for(int j=0;j<num.length;j++)
        {
            if(num[j]==i*i)
            {
                bool[j]=1;
            }
            else
            {
                if(num[j]%i==0)
                {
                    bool[j]=0;
                }
            }
            
        }
    }
    for(int i=0;i<num.length;i++)
    {
        if(bool[i]==0)
        {
            System.out.println("NO");
        }
        else
            System.out.println("YES");
    }

}
}

just check if the the given number is square of a prime number then it is T_prime.