Generate N Perfect Numbers???

EXAMPLE:

1 6
2 28
3 496
4 8128
5 33550336
6 8589869056
7 137438691328
8 2305843008139952128
9 2658455991569831744654692615953842176
10 191561942608236107294793378084303638130997321548169216
Do you expect us to do it for you? Also, your example is completely useless for someone who is not wiling to look it up or knows what a perfect number is.

http://en.wikipedia.org/wiki/Perfect_number

*edit from looking at your previous posts you seem to be trying to take advantage of these forums to pass your classes. If you are not willing to learn or put in any effort you might as well withdrawal from your classes IMHO.
Last edited on
why is this question posted twice? What is the emergency?
The problem with solving this problem is you are rapidly getting into the realm of higher and higher numbers. And you can not use floating number format because you need all the digits all the way down to the units. These numbers exceed the ability of C++ and many other languages to be held in any of the built in number formats.

So, you must develop your own way of storing them and for performing the various, necessary mathematical operations on them. Routines for addition, subtraction, multiplication, division, square roots, etc. You should do some research on how others have performed this kind of calculation. I would start by looking at how the constant Pi has been calculated to thousands of decimal places.

You may find that C++ is not the best language for this.
Last edited on
Brute force solution is to get a table of primes, first 1000 primes for example (http://primes.utm.edu/lists/small/1000.txt)

Then start iterating from 6 to inf (and avoiding prime numbers). For each number, you sum up it's prime factors and add 1 to the sum, if it equals the number, you print it.

Judging from the first 10 perfect numbers you have shown, the numbers do scale quite fast (http://en.wikipedia.org/wiki/List_of_perfect_numbers), so you can either find a big number class online or make your own or use Java's big Integer class to do this (If you must http://www.tutorialspoint.com/java/math/java_math_biginteger.htm).
Topic archived. No new replies allowed.