![]() |
|
#1
|
|||
|
|||
Help! Need Formula For Perfect NumberSince perfect numbers are very rare, it is possible that there is no perfect number in a given interval. Instead we would like to find a number which is as close as possible to the sum of its divisors. So the program will go through a certain interval (provided by the user) and return the integer in this interval which minimizes the distance to its divisors. For instance if you enter 10 and 16, the program should compute the sum of divisors for each n in [10, 16] The divisors of 10 are 1,2,5 and the sum is 8 so the distance between 10 and 8 is 10 - 8 = 2 The divisor of 11 is 1 and the sum is 1 so the distance is 11 - 1 = 10 The divisors of 12 are 1,2,3,4,6 and the sum is 16 so the distance is 16 - 12 = 4 The divisor of 13 is 1 and the sum is 1 so the distance is 13 - 1 = 12 The divisors of 14 are 1,2,7 and the sum is 10 so the distance is 14 - 10 = 4 The divisors of 15 are 1,3,5 and the sum is 9 so the distance is 15 - 9 = 6 The divisors of 16 are 1,2,4,8 and the sum is 15 so the distance is 16 - 15 = 1 And then decide that the integer n whose sum of divisors is the closest to n is 16. Indeed the distance to the sum of its divisors is just 1, which is minimal across all the distances. |
|
#2
|
|||
|
|||
Re: Help! Need Formula For Perfect NumberI guess you're going to have to calculate all the divisors for a number with a test that checks to see if a potential divisor has a remainder.
If there is a remainder, you have to kick it out and go to the next potential divisor. Sum the divisors as you go along and then once you have them all.. test to see if they are equal to the potential perfect number. |
|
#3
|
|||
|
|||
Re: Help! Need Formula For Perfect NumberThanks scrimshaw.. I am only new to this.. I know this is what I have to do..
But that is the formula that I am stuck on. How do I do that? |
|
#4
|
|||
|
|||
Re: Help! Need Formula For Perfect NumberI can work it out in my head, but not put it into the program.. I have only been doing this for a month now. I am an amatuer but I want to learn
|
|
#5
|
|||
|
|||
Re: Help! Need Formula For Perfect NumberBTW. This is my code.
I think I have almost done it...?? CPP / C++ / C Code:
Last edited by admin II : 05-Apr-2008 at 04:03.
Reason: Please surround your C++ code with [cpp] your code [/cpp]
|
Recent GIDBlog
NARMY by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Knights Tour - Reloaded . | kobi_hikri | C Programming Language | 12 | 03-Oct-2005 12:15 |
| Anyone can write a program code for this??? | chriskan76 | C Programming Language | 1 | 19-Oct-2004 20:25 |
| Array..... | chriskan76 | C Programming Language | 4 | 18-Oct-2004 14:19 |
| Apache2 config issues | monev | Apache Web Server Forum | 2 | 28-Jun-2004 06:19 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The