PyPE solution to PE problem 97

Registered by Scott Armitage

PyPE solution to PE problem 97

Blueprint information

Status:
Complete
Approver:
None
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
Approved
Series goal:
None
Implementation:
Implemented
Milestone target:
None
Started by
Scott Armitage
Completed by
Scott Armitage

Related branches

Sprints

Whiteboard

    ProjectEuler.net problem 97
    ===========================

    The first known prime found to exceed one million digits was discovered in
    1999, and is a Mersenne prime of the form 2^(6972593)-1; it contains exactly
    2,098,960 digits. Subsequently other Mersenne primes, of the form 2^(p)-1,
    have been found which contain more digits.

    However, in 2004 there was found a massive non-Mersenne prime which contains
    2,357,207 digits: 28433x2^(7830457)+1.

    Find the last ten digits of this prime number.

    Solution
    --------

    Let us denote this number as nmp = a * 2**e + n. In this case, these values
    are a = 28433, e = 7830457, and n = 1. We recognize that 2^e has many more
    digits than we are required to output, so we want to deal only with the
    digits of lower significance.

    We extract the exponent which surpasses the number of digits that we desire,
    that is, 2**m >= 10**(n_digits+1). Once we have obtained a value for m, we
    pre-compute d=2**m, f=div(e,m), and i=mod(e,m). This allows us to re-write
    nmp as nmp = a * (d**f) * (2**i) + n, which is much easier to compute.

    Answer
    ------

    8739992577

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.