We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.

# Project Euler #97: Large non-Mersenne prime

# Project Euler #97: Large non-Mersenne prime

Contest ends in

#### Sort by

recency

#### |

#### 26 Discussions

#### |

Please Login in order to post a comment

C++ SolutionObviously many languages support a native solution to this problem; so if you want to challenge yourself, don't look up how it's implemented and perhaps try to come up with some version yourself. A little wikipedia-ing on large exponentiations gives many different implementations.

Sovled in Java 8 using

`BigInteger.modPow(BigInteger exponent, BigInteger m)`

. Optimize the input, multiply/add/mod, use primitive`long`

.Incredibly easy in Python!

Lesson learned, read the output format properly. By the way, this problem is to a certain extent not as interesting as the original one, as we could play with mod cycle length in power of two, and is, as a result, not as dull as

plug in this built-in method in this language and you are done, no need to care about why it works. I doubt if such approach is plausible for the general case. (Cycle Length of Power of Two)