How to find a perfect number using mod?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mophiejoe
    New Member
    • Nov 2012
    • 1

    #1

    How to find a perfect number using mod?

    I need to find a perfect number using mod division,
    what is the formula to find it, using the if loops?
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    You mean perfect numbers as in:
    2^(p-1)(2p-1) where p is prime, such that:
    6=3+2+1
    28=7+6+5+4+3+2+ 1

    Then you only need to use Euclid's formula and prove that the value of p is prime.

    Please post your code that you've tried so far...

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      cf. http://en.wikipedia.org/wiki/Perfect_number

      since perfect numbers are relatively sparse (only 7 within the first 150 billion numbers) it were more efficient to check against that.

      alas, that’s not your task.

      you could use Euclid’s proof ( 2^(p−1) * (2^p − 1) ) for even numbers and try that factorisation, which is certainly faster than a full factorisation of the original number* (the reason digital certificates are secure—you cannot efficiently factorise a very large number) which reduces the proof to that the second factor is a Mersenne prime (of which there are 47 known).


      * - unless you’re using small numbers

      and now for the JavaScript part: JS numbers are IEEE 754 double precision floats, which means that you have 16 digits in a range of about 10^308 numbers. and having 16 decimal places is what limits you with regard to exactness. certainly it is still more efficient to look up the perfect numbers.

      yet, if you want to do a full factorisation, you’ll need the factors up to sqrt(number_to_ test). which leaves you with a loop up to 100 billion calculation cycles (only if you restrict the number to exactness level). with a rough estimate of 10,000 cycles per second, this can take about 2 - 3 hours (in which case any browser will time out the script).

      Comment

      Working...