UVA-10490 - Mr. Azad and his Son!!!!!













#include <bits/stdc++.h>
#include <fstream>
using namespace std;
int main()
{
    long long int n,p,prime,i,j,k,sum,w,a,b,m;
    while(cin>>n)
    {
        w=0;
        sum=0;
        if(n==0)
        {
            break;
        }
      m=n-1;
      prime=0;
      a=pow(2,m);
      b=pow(2,n)-1;
      p=a*b;

    for(j=2;j<=sqrt(n);j++)
    {
        if(n%j==0)
        {
            prime=1;
            w=1;
        }
    }

    if(prime==0 && n!=2 && n!=3 && n!=5 && n!=7 && n!=13 && n!=17 && n!=19 && n!=31 )
    {
        cout<<"Given number is prime. But, NO perfect number is available."<<endl;


    }
    else if(prime==1)
    {
        cout<<"Given number is NOT prime! NO perfect number is available."<<endl;
    }
    else
    {
        cout<<"Perfect: "<<p<<"!"<<endl;
    }

    }
    return 0;
}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment