Page 1 of 4
640 - Self Numbers
Posted: Mon Nov 26, 2001 7:49 pm
by henar2
Hi.
I need help with 640 problem. I wrong answered and I don't understand why.
Could someone send me the solution?
Thank you in advance.
agutierrez1@usuarios.retecal.es
Posted: Thu Dec 20, 2001 1:55 pm
by cyfra
Hi
Try do this in brutal way (check all the posibilities)
You can do this in this way:
for x=1 to 1000000 do
if (x was not used before) then
begin
Write (x)
end;
generate new number and check it as used
(you can use an array)
end;
This program should generate all the numbers.
<font size=-1>[ This Message was edited by: cyfra on 2001-12-20 12:56 ]</font>
640 Self Number WA
Posted: Sun Feb 02, 2003 9:53 am
by angga888
Help me, I'm getting WA on this problem.
How many self numbers are there below 10000 and below 50000?
Please someone answer my question and Thanks.

Posted: Tue Feb 11, 2003 7:36 am
by cytse
<10000: 983
<50000: 4895
640 _ Runtime error, help PLS.
Posted: Sat Mar 20, 2004 3:40 pm
by akhter900
My code is bellow. It generates Runtime Error. Would U help me?
==============================
#include<stdio.h>
#include<bitset>
#include<string>
#include<iostream>
using namespace std;
bitset <1000010> self_num;
long long gnrt(long long a)
{
unsigned long j = a;
while(a != 0)
{
j += a%10; a /= 10;
}
return j;
}
int main()
{
long long i, j;
for(i = 1; i <= 1000000; i++)
if(self_num.test(i) == 0)
{
printf("%ld\n", i);
j = gnrt(i) ;
self_num.set(j);
}
else
{
j=gnrt(i); self_num.set(j);
}
return 0;
}
==============================
Posted: Sun Mar 21, 2004 5:40 am
by shamim
Hi, consider this segment of your code.
[cpp]
for(i = 1; i <= 1000000; i++)
if(self_num.test(i) == 0)
{
printf("%ld\n", i);
j = gnrt(i) ;
self_num.set(j);
}
else
{
j=gnrt(i); self_num.set(j);
}
[/cpp]
when i is very large, j will be a value which is larger than the size of your bitset, hence you will get RTE when attempting to set that bit.

Volume 6 Problem640
Posted: Tue May 04, 2004 10:32 pm
by koodeGuru
In generating self numbers of base 10 I am using the recursive relation:
Initial condition is g(1)=9
My program prints 9 and then directly jumps to 97. What might be wrong with my program? Please reply.

Re: Volume 6 Problem640
Posted: Tue May 04, 2004 10:57 pm
by CDiMa
koodeGuru wrote:In generating self numbers of base 10 I am using the recursive relation:
Initial condition is g(1)=9
My program prints 9 and then directly jumps to 97. What might be wrong with my program? Please reply.

your program is right
Code: Select all
g(2)=8*10^(2-1)+g(1)+8=8*10+9+8=97
Ciao!!!
Claudio
I knew it
Posted: Wed May 05, 2004 5:58 am
by koodeGuru
I knew that I was getting appropriate output. But how do I print out all self numbers less than 1000000. Do I have to use a different recursive relation?Thanks.
I knew it
Posted: Wed May 05, 2004 6:07 am
by koodeGuru
I knew that I was getting appropriate output. But how do I print out all self numbers less than 1000000. Do I have to use a different recursive relation?Thanks.
Re: I knew it
Posted: Fri May 07, 2004 10:22 am
by CDiMa
koodeGuru wrote:I knew that I was getting appropriate output. But how do I print out all self numbers less than 1000000. Do I have to use a different recursive relation?Thanks.
Basically self(n+1)=self(n)+11.
You only need some extra care when you step over multiples of 10^n with n>=2.
Ciao!!!
Claudio
Posted: Wed Jul 28, 2004 5:00 pm
by Pavl0
U can also check all number if it is self number

J get AC by deleting numbers who are not self number's
Posted: Thu Aug 26, 2004 1:17 pm
by Arm.Turbo
Here is my code I don't understand why it's WA. Help me pls.
[cpp]Spoiler[/cpp]
Posted: Thu Aug 26, 2004 7:09 pm
by Ryan Pai
Arm.Turbo,
You are only adding five digits, whereas the numbers can be up to six digits.
Posted: Fri Aug 27, 2004 7:11 am
by Arm.Turbo
999943
999945
999956
999967
999978
999989
My last numbers are they correct?