02-05-2013, 06:22 PM
i was trying to write a code for finding perfect numbers but I cannot seem to get it working. any ideas?
Function find_perfect_numbers
Function find_perfect_numbers
Finding "perfect" numbers
|
02-05-2013, 06:22 PM
i was trying to write a code for finding perfect numbers but I cannot seem to get it working. any ideas?
Function find_perfect_numbers
02-05-2013, 07:33 PM
02-05-2013, 10:24 PM
this works for the first 5 but not sure how wise it is to use array for numbers larger than 4th perfect number (6,28,496,8128,33550336). best of luck to ya.
Function find_perfect_numbers2
02-06-2013, 03:40 AM
tweaked it a little array only populated now with the exact amount of elements it needs to hold divisor numbers.
Function find_perfect_numbers3 int sn cn ii fnc i You May have to change array type as u get into larger numbers though.but this is not the best way to test either and is limited in how far it can go. http://www.mersenne.org/ has software just for doing this
02-06-2013, 06:41 AM
02-07-2013, 04:31 AM
last post on this.
This will do the first 8 and would do more if had a large enough number range, but can only do the first 8 ;Perfect Number = 2^(n-1) * (2^n - 1) out ARRAY(str) mpn mpn="2[]3[]5[]7[]13[]17[]19[]31[]61[]89[]107[]127[]521[]607[]1279[]2203[]2281[]3217[]4253[]4423[]9689[]9941[]11213[]19937[]21701[]23209[]44497[]86243[]110503[]132049[]216091[]756839[]859433[]1257787[]1398269" long n i x for i 0 8;; number goes out of range after 8. ,n=val(mpn[i]) ,x=pow(2 (n-1)) * (pow(2 n)-1) ,out x ;;output ;;6 ;;28 ;;496 ;;8128 ;;33550336 ;;8589869056 ;;137438691328 ;;2305843008139952128 wont show the whole ARRAY here.The rest of it after 86243 is []110503[]132049[]216091[]756839[]859433[]1257787[]1398269" but really only need up to 31 after that number is too big |
« Next Oldest | Next Newest »
|