Qbasicnews.com

Full Version: Complete numbers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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
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.
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.
I'm sorry, but you are wrong Meg. Look at
http://www-gap.dcs.st-and.ac.uk/~history...mbers.html
For a brief about the perfect numbers.

In short there's no proof, yet, that all the perfect numbers are like you say.