#include<stdio.h>
#include<math.h>
int main()
{
int a[100],i,j,k,p,b[100];
for(i=2;i<=31;i++)
{
b[i]=0;
a[i]=0;
}
a[1]=1;
b[11]=1;
b[23]=1;
b[29]=1;
p=sqrt(31);
for(j=2;j<=p;j++)
{
for(k=2;j*k<31;k++)
{
a[j*k]=1;
b[j*k]=1;
}
}
int n,m;
long long int x,z,result;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
if(a[n]==0)
{
m=n-1;
x=pow(2,m);
z=pow(2,n);
result=x*(z-1);
if(b[n]==0)
printf("Perfect: %lld!\n",result);
else
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 0;
}
#include<math.h>
int main()
{
int a[100],i,j,k,p,b[100];
for(i=2;i<=31;i++)
{
b[i]=0;
a[i]=0;
}
a[1]=1;
b[11]=1;
b[23]=1;
b[29]=1;
p=sqrt(31);
for(j=2;j<=p;j++)
{
for(k=2;j*k<31;k++)
{
a[j*k]=1;
b[j*k]=1;
}
}
int n,m;
long long int x,z,result;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
break;
if(a[n]==0)
{
m=n-1;
x=pow(2,m);
z=pow(2,n);
result=x*(z-1);
if(b[n]==0)
printf("Perfect: %lld!\n",result);
else
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 0;
}
No comments:
Post a Comment