Large integer multiplication could be faster.
Created originally on Bitbucket by smitho (Oscar Smith)
I have noticed that multiplication of large integers (2^1000 or greater) , while faster than
python is a good bit slower than for integers provided by gmpy2. This is a pretty minor request, as not much code uses numbers this big, but it would be great to have better support.
#!python def mod_mersenne(n, prime, mersenne_prime): """ Calculates n % 2^prime-1 where mersenne_prime=2**prime-1 """ while n > mersenne_prime: n = (n & mersenne_prime) + (n >> prime) return n if n != mersenne_prime else 0 def is_mersenne(prime= 9883) mersense_prime = 2**prime - 1 s = 4 for _ in range(prime - 2): s = mod_mersenne(s*s, prime, mersenne_prime) - 2 return s % mersenne_prime == 0: