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

Moderator: Board moderators

Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am
Contact:

### Good Help

Yeh Sedefcho
You Are Right I do the Same & Got ACC..
Thanks.

RC's
Learning poster
Posts: 65
Joined: Fri Jul 13, 2007 3:17 pm
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 ?

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:
A number is perfect is sum of its divisors equals itself.
For example, sum of the three divisors of 6: 1+2+3 is 6, and so 6 is perfect.

All even perfect numbers are always of the form 2^{n-1} (2^n-1), where 2^n-1 is a prime - such primes are called Mersenne primes.

nalb
New poster
Posts: 1
Joined: Mon Apr 28, 2008 8:41 am

### 10490 - Mr. Azad and His Son!!!!!

HEEEELLP !!I send my code :

#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 ...

atul
New poster
Posts: 7
Joined: Thu Sep 27, 2012 4:21 pm

### Re: 10490 - Mr. Azad and His Son!!!!!

Why WA?????????
Plz help me.
I have tested all cases but why WA.

#include <iostream>
#include <cmath>
#include <cstdio>
#define mx 100
using namespace std;

int main()
{

int n;
bool prime[mx];
for(int i = 2; i <= 40; i++){
if(prime == false )
for(int j = i*i; j <= 40; j += i){
prime[j] = true;
}
}
unsigned long long int a, b, c;
while(cin >> n){
if(n == 0){
break;
}
if(n == 31){
cout << "Perfect: 2305843008139952128!" << endl;
}
else{
bool flag = false;
b = (pow(2, n) - 1);
c = (pow(2, n) - 1);
a = (pow(2, n-1)*(pow(2, n)-1));
for(long int i = 2; i * i<= c ; i++){
if(b % i == 0){
flag = true;
break;
}
}
if(flag == false && prime[n] == false){
cout << "Perfect: " << a << "!" << endl;
}
else if(prime[n] == false)
cout << "Given number is prime. But, NO perfect number is available." << endl;
else
cout << "Given number is NOT prime! NO perfect number is available." << endl;
}

}
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10490 - Mr. Azad and His Son!!!!!

It looks like you figured it out.
Check input and AC output for thousands of problems on uDebug!