I saw that many people had solved this one. Must be easy. It was. I suppose the challenge would be to get it down to as fast as possible. So I employed a simple power of 2 bit-hack and go it down to 14 minutes, with the core-code down to 9 lines. I suppose I could do much better given time & energy, but hey, it works fine.

#Euler97
class Problem:
def Solution(self):
a = 1 << 100000
M = 1
for i in range (0,78):
M *= a
M = (M * (1 << 30457) * 28433) + 1
Mersenne = str(M)
size = len(Mersenne)
for i in range(size-10,size):
print Mersenne[i],
if __name__ == '__main__':
P = Problem()
P.Solution()

### Like this:

Like Loading...

*Related*