Python Implementation of Problem 97

View source code here on GitHub!

Problem Solution

Project Euler Problem 97

This one ended up being fairly easy to run, since Python integers can be an arbitrary size

Problem:

The first known prime found to exceed one million digits was discovered in 1999, and is a Mersenne prime of the form 26972593−1; it contains exactly 2,098,960 digits. Subsequently other Mersenne primes, of the form 2p−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: 28433×27830457+1.

Find the last ten digits of this prime number.

python.src.p0097.main() int
 1"""
 2Project Euler Problem 97
 3
 4This one ended up being fairly easy to run, since Python integers can be an
 5arbitrary size
 6
 7Problem:
 8
 9The first known prime found to exceed one million digits was discovered in
101999, and is a Mersenne prime of the form 26972593−1; it contains exactly
112,098,960 digits. Subsequently other Mersenne primes, of the form 2p−1, have
12been found which contain more digits.
13
14However, in 2004 there was found a massive non-Mersenne prime which contains
152,357,207 digits: 28433×27830457+1.
16
17Find the last ten digits of this prime number.
18"""
19
20
21def main() -> int:
22    return ((28433 << 7830457) + 1) % 10**10

Tags: prime-number, large-numbers