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

All about problems in Volume 104. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

Good Help

Post by Rocky »

Yeh Sedefcho
You Are Right I do the Same & Got ACC..
Thanks. :lol:
RC's
Learning poster
Posts: 65
Joined: Fri Jul 13, 2007 3:17 pm

Post by RC's »

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:

Post by mf »

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!!!!!

Post by nalb »

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!!!!!

Post by atul »

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!!!!!

Post by brianfry713 »

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

Return to “Volume 104 (10400-10499)”