[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ProgSoc] Perfect Number Alg...



An integer is said to be a perfect number if all its factors, including 1
(but not the number itself), sum to that number. For example, 6 is a
perfect number because 6 = 1 + 2 + 3.

How would I write a function "perfect" that determines if the parameter
"number" is a perfect number. And use this function in a program that
determines and prints all the perfect numbers between 1 and 10000. Also, print all the factors
of each perfect number in order to confirm that the number is indeed
perfect.

The Greek mathematician Euclid discovered that the first four perfect
numbers are generated by the formula 2^(n-1) *(( 2^n)-1):

for n = 2:
2^1((2^2)-1)=6

for n = 3:
2^2((2^3)-1)=28=1+2+4+7+14

for n = 5:
2^4((2^5)-1)=496

for n = 7:
2^6((2^7)-1)=8128

Noticing that (2^n)-1 is a prime number in each instance, Euclid proved
that the formula 2^(n-1)*((2^n)-1) gives a perfect even number whenever
(2^n)-1 is prime.

I've spent 2 days attempting to create a function in Applescript which
I'll later translate into C (Basically using Applescript as my sudo
code)...

I'm ok with proving whether a number is perfect or not. I'm just stuck
on how to get then print all the factors of each perfect number in order
to confirm that the number is indeed perfect.

Any help would be much appreciated.

~ Marcus :)

-
You are subscribed to the progsoc mailing list. To unsubscribe, send a
message containing "unsubscribe" to progsoc-request@xxxxxxxxxxxxxxxxxxx
If you are having trouble, ask owner-progsoc@xxxxxxxxxxxxxxxxxx for help.