640 - Self Numbers

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

Moderator: Board moderators

henar2
New poster
Posts: 30
Joined: Mon Nov 26, 2001 2:00 am
Location: Valladolid (Spain)

640 - Self Numbers

Post by henar2 » Mon Nov 26, 2001 7:49 pm

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

cyfra
Experienced poster
Posts: 144
Joined: Thu Nov 22, 2001 2:00 am
Location: Gdynia, Poland

Post by cyfra » Thu Dec 20, 2001 1:55 pm

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>

User avatar
angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia

640 Self Number WA

Post by angga888 » Sun Feb 02, 2003 9:53 am

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. :D

User avatar
cytse
Learning poster
Posts: 67
Joined: Mon Sep 16, 2002 2:47 pm
Location: Hong Kong
Contact:

Post by cytse » Tue Feb 11, 2003 7:36 am

<10000: 983
<50000: 4895

akhter900
New poster
Posts: 7
Joined: Fri Mar 19, 2004 3:27 pm

640 _ Runtime error, help PLS.

Post by akhter900 » Sat Mar 20, 2004 3:40 pm

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;
}
==============================
AkHtEr

User avatar
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim » Sun Mar 21, 2004 5:40 am

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. :wink:

koodeGuru
New poster
Posts: 23
Joined: Mon Apr 19, 2004 6:24 am

Volume 6 Problem640

Post by koodeGuru » Tue May 04, 2004 10:32 pm

In generating self numbers of base 10 I am using the recursive relation:

Code: Select all

g(n)=8*10^(n-1)+g(n-1)+8;
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. :(

CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

Re: Volume 6 Problem640

Post by CDiMa » Tue May 04, 2004 10:57 pm

koodeGuru wrote:In generating self numbers of base 10 I am using the recursive relation:

Code: Select all

g(n)=8*10^(n-1)+g(n-1)+8;
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

koodeGuru
New poster
Posts: 23
Joined: Mon Apr 19, 2004 6:24 am

I knew it

Post by koodeGuru » Wed May 05, 2004 5:58 am

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.

koodeGuru
New poster
Posts: 23
Joined: Mon Apr 19, 2004 6:24 am

I knew it

Post by koodeGuru » Wed May 05, 2004 6:07 am

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.

CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

Re: I knew it

Post by CDiMa » Fri May 07, 2004 10:22 am

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

User avatar
Pavl0
New poster
Posts: 16
Joined: Sun Apr 18, 2004 2:57 pm

Post by Pavl0 » Wed Jul 28, 2004 5:00 pm

U can also check all number if it is self number :)
J get AC by deleting numbers who are not self number's

Arm.Turbo
New poster
Posts: 21
Joined: Wed Aug 11, 2004 1:20 pm

Post by Arm.Turbo » Thu Aug 26, 2004 1:17 pm

Here is my code I don't understand why it's WA. Help me pls.

[cpp]Spoiler[/cpp]
Last edited by Arm.Turbo on Fri Aug 27, 2004 12:17 pm, edited 1 time in total.

Ryan Pai
Learning poster
Posts: 67
Joined: Fri Jul 04, 2003 9:59 am
Location: USA
Contact:

Post by Ryan Pai » Thu Aug 26, 2004 7:09 pm

Arm.Turbo,
You are only adding five digits, whereas the numbers can be up to six digits.
I'm always willing to help, if you do the same.

Arm.Turbo
New poster
Posts: 21
Joined: Wed Aug 11, 2004 1:20 pm

Post by Arm.Turbo » Fri Aug 27, 2004 7:11 am

999943
999945
999956
999967
999978
999989

My last numbers are they correct?

Post Reply

Return to “Volume 6 (600-699)”