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");
        }
    }


}

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.