Can someone tell me why doesn't it work?


#1

bool isPrime(int n)
{
if (n <= 1)
return false;

// Check from 2 to n-1 
for (int i = 2; i < n; i++) 
    if (n % i == 0) 
        return false; 

return true; 

}
// Function to find primes
vector findPrime(int n)
{
vector ret;
for (int i = 2; i <=n; i++) {
if (isPrime(i))
ret.push_back(i);

}
return ret;

}

int Solution::isPower(int A) {
double lim=sqrt(A);
if(isPrime(A)) return 0;
vector prime;
prime=findPrime(lim+1);

for(auto i:prime){
    int flag=0;
    //int temp=A;
    while(A%i==0 && A>0){
        flag=!flag;
        A=A/i;
    }
    if(flag!=0) return 0;
}
return 1;

}