Perfect Numbers

Johan Schoeman

Expert
Licensed User
Longtime User
If your device is bored at night while you are sleeping, give it the attached project to work on while you are sleeping and see how far it got by the time that you get up in the morning. Finding just the first 5 perfect numbers. The first 4 can be found in less than 4 seconds. As for the fifth....well, that is going to take some time.

Perfect numbers are numbers where the factors of the number (excluding the number itself) add to the number:

eg factors of 6 are 1, 2, and 3 = 6 (therefore 6 is a perfect number)
eg factors of 28 are 1, 2, 4, 7, 14 = 28 (therefore 28 is a perfect number)
etc

My device will take approximately 29 hours to calculate the 5th perfect number (it being 33,550,336)

The last discovered perfect number has 34,850,340 digits. It was discovered in 2013 by Cooper, Woltman, Kurowski, et al.
 

Attachments

  • PerfectNumbers.zip
    11.3 KB · Views: 197
Last edited:

wonder

Expert
Licensed User
Longtime User
Sounds interesting, but why inline Java? Does it make it faster?

I'm using B4A 4.00, so no Java for me... :(
I'll be upgrading soon, though.
 

Johan Schoeman

Expert
Licensed User
Longtime User
Sounds interesting, but why inline Java? Does it make it faster?

I'm using B4A 4.00, so no Java for me... :(
I'll be upgrading soon, though.
Found the code on the web. Should be simple to convert to B4A. Have not checked if B4A code will be faster (although I guess it will be pretty much the same). I am watching my device and see that it has only got to 360 000 in about an hour....:(
 

sorex

Expert
Licensed User
Longtime User
what kind of device is that, @Johan Schoeman ?

I wrote my own routine that might be faster on big numbers and my low end Samsung Ace phone went to 1.000.000 already in 2 hours. (or was it 3)

I just added a gui to track timing and ran it on a tablet aswell which seems a lot faster already.

I let you know how long it took if it can match that 5th number and if my time math is right. (the first 4 were instant so I couldn't double check that code)
 

sorex

Expert
Licensed User
Longtime User
it seems that 29 hours was very optimistic and it might need a few days :)

the tablet is at 3.000.000 after 6 hours so barely at 10% to get to the next number.

it's needless to say that it gets slower the bigger the number gets.
 

ilan

Expert
Licensed User
Longtime User
hi johan

I am not sure I have understood what is a perfect number

what I understood is you take the number and try to see if the numbers lower then the number together will become the number...

like 6 = 1 + 2 + 3 then 6 is a perfect number

so you can just calculate 1+2+3+4+5+6+7+8+9+10+11+12+13..... and the result is also a perfect number right? why calculate from the end and try to see if its a perfect number calculate from the beginning ...

or am I wrong?? :confused:
 

Johan Schoeman

Expert
Licensed User
Longtime User
hi johan

I am not sure I have understood what is a perfect number

what I understood is you take the number and try to see if the numbers lower then the number together will become the number...

like 6 = 1 + 2 + 3 then 6 is a perfect number

so you can just calculate 1+2+3+4+5+6+7+8+9+10+11+12+13..... and the result is also a perfect number right? why calculate from the end and try to see if its a perfect number calculate from the beginning ...

or am I wrong?? :confused:
No Ilan. You need to get all the integer factors of the number and add them together. If they total to the number itself then the number is a perfect number. Take 28 for eg:

28 is only divisible by 1, 2, 4, 7, 14, and 28 (without any remainders). But you need to only take the integer factors that are smaller than the number itself (thus excluding 28)
1 + 2 + 4 + 7 + 14 = 28
So, 28 is a perfect number.

Hope it makes it a bit clearer...:)
 

ilan

Expert
Licensed User
Longtime User
Ok now i understand :) thanx for making it clear for me

I will see if i can find the biggest perfect number :D
 

Johan Schoeman

Expert
Licensed User
Longtime User
I hope you have a few decades left to keep the app running ;)
Here is a piece of code that I found that spits out the first 13 perfect numbers in probably a minute or so. Note that the 13th perfect number has 314 digits. It looks like this:

23562723457267347065789548996709904988477547858392600710143027597506337283178622239730365539602600561360255566462503270175052892578043215543382498428777152427010394496918664028644534128033831439790236838624033171435922356643219703101720713163527487298747400647801939587165936401087419375649057918549492160555646976

Reported 100% correct in the log by my Samsumg GT-P3100 tablet

Increase the value of integer variable numb in the B4A code (from 12 to 13) to calculate the 14th perfect number. Have not tested "numb" values > 12 as yet.

Edit: got the 14th one in under 2 minutes. It has 366 digits and looks like this:

141053783706712069063207958086063189881486743514715667838838675999954867742652380114104193329037690251561950568709829327164087724366370087116731268159313652487450652439805877296207297446723295166658228846926807786652870188920867879451478364569313922060370695064736073572378695176473055266826253284886383715072974324463835300053138429460296575143368065570759537328128

See here for a list to compare with
 

Attachments

  • PerfectNumbers.zip
    12.4 KB · Views: 190
Last edited:

sorex

Expert
Licensed User
Longtime User
after 16 hours just below 6.000.000 :)

the even trick is indeed a speedup but on the wiki they wrote that they haven't found an uneven one yet which doesn't mean there isn't one coming up.
 

sorex

Expert
Licensed User
Longtime User
I guess we'll need a big cluster of 32+ cores servers to speed it up a little ;)
 

Johan Schoeman

Expert
Licensed User
Longtime User
I guess we'll need a big cluster of 32+ cores servers to speed it up a little ;)
I have just for fun started looking for the first 20 with the project in post #10. Starting time was 18:30:16 local time. It is now 20:13 and it is still thinking about this one. It has 2663 digits and was discovered in 1961 by some guy with the surname of Hurwitz.
 
Last edited:

sorex

Expert
Licensed User
Longtime User
yeah, amazing how these math/number freaks found all these things (not only perfect numbers tho) centuries ago.

they didn't have tv's & internet , so they must have used their time better ;)
 

Johan Schoeman

Expert
Licensed User
Longtime User
Looking for the first 23 perfect numbers. Starting time is 20:47:09. Will see if it managed to crunch it out by 04h30 tomorrow morning. I have all faith in my Samsumg tablet to be able to do so....:rolleyes:
 

WAZUMBi

Well-Known Member
Licensed User
Longtime User
Hey Erel this sounds like an interesting 'challenge' question for the forum...
 

Johan Schoeman

Expert
Licensed User
Longtime User
Looking for the first 23 perfect numbers. Starting time is 20:47:09. Will see if it managed to crunch it out by 04h30 tomorrow morning. I have all faith in my Samsumg tablet to be able to do so....:rolleyes:
When I left this morning at 04h30 "old faithful" was still crunching the numbers to try and find the first 23. Left it on to run while I am away from home today and will check tonight when I get home around 21h00.
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Have you prepared yourself to coming home to a pile of molten plastic? :p
 

Johan Schoeman

Expert
Licensed User
Longtime User
Have you prepared yourself to coming home to a pile of molten plastic? :p
Back home. No sign of a pile of molten plastic. Still running. See task manager indicates that the CPU is idling along at about 50% - which is actually P*&^%! me off because it could have been twice as far as what it is at present if it pulled its weight today while I was away. And to think it basically sat here on my desk in idle mode all day long and was happily chewing away on the electricity that I have to pay for while doing nothing? This is not on! I am going to fetch a hammer and threaten this lazy CPU to start working at full pace right now...really, 50% is being extremely lazy...No wonder there is not a pile of molten plastic on my desk. 50% with no answer - unacceptable. Molten plastic with an answer in the log - priceless!
 
Top