Qbasicnews.com
May 30, 2020, 11:02:55 AM
 Pages: [1]
 Author Topic: Complete numbers  (Read 3228 times)
Zap
Been there, done that

Posts: 1124

 « on: August 25, 2003, 12:00:38 PM »

Challenge: Find all complete numbers between 0 and 500, as fast and simple, while presenting it in a comfortable way.

Complete numbers? Well, actually I don't know if its ther correct translation, but a complete number is a number where the sum of all divisors is  equal to the number itself. Eg: '6'. 6 can be divided by 1, 2, and 3 (6 doesn't count), and 1+2+3=6.

You can't use ASM or libs, not that I can see why you want to, and code simplicity values over speed, at least to a certain point.

/Zap
 Logged

url=http://www.copy-pasta.com]CopyPasta[/url] - FilePasta
xhantt
Member

Posts: 90

 « Reply #1 on: August 25, 2003, 12:30:57 PM »

The correct tranlation is "perfect numbers". Now let me try:

Code:
DEFINT A-Z
FOR i = 2 TO 500
d = 2
s = 1
WHILE d * d < i
IF i MOD d = 0 THEN
s = s + d + i / d
END IF
d = d + 1
WEND
IF d * d = i THEN
s = s + d
END IF
IF i = s THEN
PRINT i; " is a perfect number"
END IF
NEXT i
 Logged
Meg
Ancient QBer

Posts: 483

 « Reply #2 on: August 26, 2003, 08:51:33 AM »

one way to increase efficiency of this is to only check even numbers ending in 6 and 8.  I think i remember reading that all perfect numbers were like that..

Code:
n& = -2
DO
n& = n& + 8
(check for perfect number)
n& = n& + 2
(check for perfect number)
LOOP UNTIL (exit clause)

*peace*

Meg.
 Logged
Meg
Ancient QBer

Posts: 483

 « Reply #3 on: August 26, 2003, 08:54:37 AM »

i could be totally wrong about what your code is doing, so let me try again..

that would be a more efficient way of checking numbers *IF* your program is going through one by one and checking every number.  I don't know what xhantt's code is up to, so don't think of my code as improving on his, 'cause he's prolly doin' something entirely different.

lol.  math.

*peace*

Meg.
 Logged
xhantt
Member

Posts: 90

 « Reply #4 on: August 27, 2003, 05:53:45 PM »

I'm sorry, but you are wrong Meg. Look at
http://www-gap.dcs.st-and.ac.uk/~history/HistTopics/Perfect_numbers.html
For a brief about the perfect numbers.

In short there's no proof, yet, that all the perfect numbers are like you say.
 Logged
 Pages: [1]