Parfait

Looks for perfect numbers.

Description

Looks for perfect numbers (numbers which divisors (except number itself) other than themself) sum give themself).
Example: 6 divisors are: 1, 2, 3. And 1 + 2 + 3 = 6.

Perfect numbers I've found are: 6, 28, 496, 8128 and 33 550 336.

You can give as parameter a number from which research starts.

Special thanks to Pierre Barbier de Reuille for improving my algorithm, program runs fery fast!

Example

flashcode@home> parfait
Nombre parfait: 6 (1+2+3)
Nombre parfait: 28 (1+2+4+7+14)
Nombre parfait: 496 (1+2+4+8+16+31+62+124+248)
Nombre parfait: 8128 (1+2+4+8+16+32+64+127+254+508+1016+2032+4064)
Recherche... 105200

flashcode@home> parfait 33550336
Nombre parfait: 33550336 (1+2+4+8+16+32+64+128+256+512+1024+2048+4096+8191+16382+32764+65528+131056+262112+524224+1048448+2096896+4193792+8387584+16775168)
Recherche... 33550400

Download

C source with compiled version for Linux, Dos / Windows: parfait.zip (24.9 KB)