Blue Bridge Cup Daily One Question (9): Mersenne Prime Numbers (python)

Topic:

If the sum of all true factors of a number is equal to itself, it is called a "perfect number" or "perfect number".
For example: 6 = 1 + 2 + 3
28 = 1 + 2 + 4 + 7 + 14
as early as 300 BC For many years, Euclid gave the theorem for determining perfect numbers:
if 2^n-1 is a prime number, then 2^(n-1) * (2^n-1) is a perfect number.
Among them, ^ means "power" operation, the priority of power is higher than the four arithmetic operations, for example: 2^3 = 8, 2 * 2^3 = 16, 2^3-1 = 7,
but people quickly discovered that when n When it is very large, it is still difficult to determine whether a large number is prime or not.
Because of the conjecture of the French mathematician Mason, we are accustomed to call the prime numbers of the form: 2^n-1: Mersenne prime numbers.

As of February 2013, only 48 Mersenne prime numbers have been found. The newly found Mersenne prime number is too large to get a complete picture of it with general programming ideas, so we reduce the difficulty of the task a bit:
In 1963, the University of Illinois, USA, to commemorate the 23rd Mersenne prime number n=11213 they found, The words "2^11213-1 is a prime number" are printed on every envelope sent out.
2^11213-1 This number is already very large (more than 3000 digits), please program to find the last 100 digits of the decimal representation of this prime number.

Solution:
In fact, the last one hundred digits of 2^11213-1 are
calculated and converted into a string type slice.

Code:

a = str(2 ** 11213 - 1)
print(a[-100:])

Answer:
8586718527586602439602335283513944980064327030278104224144971883680541689784796267391476087696392191

Guess you like

Origin blog.csdn.net/weixin_50791900/article/details/112660732