Problem #97 Difficulty: 5%

Large Non-Mersenne Prime

Solution Language: Python

The problem

Find the last ten digits of the prime 28433 × 2⁷⁸³⁰⁴⁵⁷ + 1, which has over 2.3 million digits.

My solution

The whole thing is three lines of Python 2, and it computes the full number:

a = 28433*(2**7830457)

print a+1

Python’s integers have arbitrary precision, so this simply builds the entire 2,357,207-digit number and prints it. I read the last ten digits off the end of the output. There’s no modular arithmetic involved.

The arithmetic itself is fast. Most of the running time goes into converting the 2.3-million-digit result to decimal for printing.