I'm confused with this problem.
It is said that perfect number is 2^(k-1)*(2^k-1).
Then for what k values that does not have perfect number ?
What is the requirement of a perfect number ?
#include <stdio.h>
#include <math.h>
bool V[46344];
int main()
{
for(int i=2;i<=46342;i++)
V[i]=1;
for(int i=2;i*i<=46342;i++)
{
if(V[i]==1)
{
for(int j=i;i*j<=46342;j++)
V[i*j]=0;
}
}
unsigned long h;
long long k;
int n;int sw;
while(true)
{
scanf("%d",&n);
if(n==0)
break;
h=(long long)(pow((double)(2),(double)(n))-1);
sw=1;
for(long i=2;i*i<=h;i++)
{
if(V[i]==1 )
{
if((h%i)==0)
{sw=0;break;}
}
}
if(sw==1)
{
k=h*(long long)(pow((double)(2),(double)(n-1)));
printf("Perfect: %I64d!\n",k);
}
else
{
if(V[n]==1)
printf("Given number is prime. But, NO perfect number is available.\n");
else
printf("Given number is NOT prime! NO perfect number is available.\n");
}
}
return 1;
}
but the judge say's [b]Runtime error[/b] but the [b]Run Time[/b] is 0.000 i don't understand please help me what's wrong ...