UVA 10490 - Mr. Azad and his Son!!!!! Solution
Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<stdio.h>
#include<math.h>
int main ()
{
long long int n,s,flag1,flag=0,i,a,j,sum=0;
while(scanf("%lld",&n)!=EOF)
{
if(n==0)
break;
a=sqrt(n);
sum=0;
flag=0;
for(i=2; i<=a; i++)
{
if(n%i==0)
flag++;
}
s=(pow(2,(n-1))*(pow(2,n)-1));
if(n==2||n==3||n==5||n==7||n==19||n==31||n==13||n==17)
printf("Perfect: %lld!\n",s);
else
{
if(flag==0)
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");
}
}
}
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<stdio.h>
#include<math.h>
int main ()
{
long long int n,s,flag1,flag=0,i,a,j,sum=0;
while(scanf("%lld",&n)!=EOF)
{
if(n==0)
break;
a=sqrt(n);
sum=0;
flag=0;
for(i=2; i<=a; i++)
{
if(n%i==0)
flag++;
}
s=(pow(2,(n-1))*(pow(2,n)-1));
if(n==2||n==3||n==5||n==7||n==19||n==31||n==13||n==17)
printf("Perfect: %lld!\n",s);
else
{
if(flag==0)
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");
}
}
}
No comments