I am getting a runtime here for the test case A=1024000000


#1

I am getting a runtime here for the test case A=1024000000
#define ll long long
int Solution::isPower(int A) {
if(A==1)
{
return 1;
}
if(A==2||A==3)
{
return 0;
}
ll sieve[A+1];
for(int i=0;i<=A;i++)
{
sieve[i] = 1;
}
sieve[0]=1;
sieve[1]=1;
for(int i=2;ii<=A;i++)
{
if(sieve[i]==1)
{
for(int j=2
i;j<=A;j+=i)
{
sieve[j] = sieve[j]*i;
}
}
}
ll mynum = sieve[A];
int count=0;
while(A!=1 && (A%(int)mynum)==0)
{
count++;
A=A/(int)mynum;
}
if(count>1)
{
return 1;
}
else{
return 0;
}
}


#2

You cannot make array of size 1024000000 in case of this testcase.So it’s giving run time error.
Maximum permissible array size is 1000000.


#3

@anim_ated check this out, may be this could help


#4

int Solution::isPower(int A) {

int n=A;

if(n==1)
    return true;
for (int i=2; i<=sqrt(n); i++) 
{ 
    unsigned long long p=i;
    while(p<=n)
    {
        p=p*i;
        if(p==n)
            return true;
    }
} 
return false;

}


#5

Can you please explain in details about this approach?