1
头图

Accidentally, I saw such a story in Teacher Wu Jun's "Top of the Tide (Fourth Edition)".

Google once used a large billboard on California's 101 Freeway to advertise this:

{the first ten consecutive prime numbers in the irrational number e}.com

If you know the answer (7427466391.com), you can enter Google's recruitment website through the above URL. And to be able to figure this out, you have to be smart.

"very smart"? Teacher Wu Jun's words made people interested, and he also used the power of the computer to ponder this proof question.

What Google's Genius Billboard From 2004 Can Teach Us About Solving Problems


ideas

Everyone knows that e is an irrational number, in other words, an infinite non-repeating decimal. There are always some mathematics enthusiasts in the world who are always happy to use computers to calculate the decimal places of these irrational numbers, such as π, and e is no exception. so,

first step is to find the decimal place data of e on some authoritative mathematical websites;

At this time, Google Dafa is done, and I came to the Wikipedia page of e. I noticed the "A001113" hyperlink behind the decimal expression of e below. If there is something strange, I clicked to see it.

image-20220111002852190

Then there is the A001113 page of this OEIS site, which turns out to be a very authoritative database website in number theory.

image-20220111003231427

Scanning this webpage with the eyes of treasure hunters, I finally found the target. That's it for the first entry in LINKS.

N. J. A. Sloane, Table of 50000 digits of e labeled from 1 to 50000 [based on the ICON Project link below]

The author is also NJA Sloane, who founded this OEIS organization. It seems that he is a big man in this field. Sorry for not knowing Taishan.

image-20220111004139733

Click into this Table of 50000 digits of e labeled from 1 to 50000 , and the page results are pleasing. Direct plain text data, the left column is the number of decimal places, and the right column is the corresponding value. When the data is obtained, the follow-up work can be carried out simply by processing it. I hope the answer to this proof question is in the 50,000 numbers, otherwise the scope will have to be expanded.

image-20220111004824130

At this point, the decimal place data of the e irrational number is available, and the next step can be started.

second step, how to judge a number is prime?

Since elementary school, mathematics teachers have taught us that the definition of a prime number is a natural number greater than 1 that cannot be divisible by other natural numbers except 1 and the number itself. So naturally, the idea of judging is to judge whether 2 → n can divide n evenly for a natural number n greater than 1. If it is found that a number can divide n, then n is not a prime number, otherwise it is. In addition, considering the symmetry, we do not have to increase to n all the time. For example, for 2*3 and 3*2, 6/2 and 6/3 both determine that 6 is a composite number, but it is sufficient to increase to 2. Therefore, there is no need to consider 3.

The Python code is as follows:

def isPrime(n: int) -> bool:
  if n <= 1:
    return False
  i = 2
  # Make use of symmetry. For example, 2*3=6, 3*2=6
  while i * i < n:
    if n % i == 0:
      return False
    i += 1
  return True

When looking up information about prime numbers on the Internet, I found that there is a distribution law of prime numbers in number theory that can also be used to judge prime numbers. Source - Prime Number Judgment Algorithm

Prime Number Distribution Law:

When n >= 5, if n is a prime number, then n % 6 = 1 || n % 6 = 5, that is, n must appear on both sides of 6x (x ≥ 1). In other words, any prime number can be represented in the form 6x ± 1, x ∈ N .

Proof:

Represent numbers around 6x in the following way:

......(6x - 1), 6x, 6x + 1, 2(3x + 1), 3(2x + 1), 2(3x + 2), 6x + 5, 6(x+1)......

The numbers not on either side of 6x are: 2(3x + 1), 3(2x + 1), 2(3x + 2), they are not prime numbers, so prime numbers appear on both sides of 6x.

The Python code is implemented as follows, and the time complexity is almost the same as the previous one, but it is enough for our proof.

def isPrime(n: int) -> bool:
  if n <= 1:
    return False
  if n <= 3:
    return True
  # For case of 2(3x + 1), 3(2x + 1), 2(3x + 2)
  if n % 2 == 0 or n % 3 == 0:
    return False
  # For case of the multiplication of prime numbers
  i = 5
  while i * i < n:
    if n % i == 0 or n % (i + 2) == 0:
      return False
    i += 6
  return True

In addition, I learned that it is very useful to determine prime numbers in cryptography, such as the famous RSA algorithm. In terms of judging the prime number algorithm, the above simple remainder algorithm with high time complexity is not used, but Fermat's little theorem, Miller-Rabin algorithm and Solovay-Strassen algorithm, etc., which are more difficult to understand. For details, please refer to the following article Article - PyCrypto Cryptography Library Source Code Analysis (1) Random number and large prime number generation , and the above one.

At this point, the necessary materials are ready, and the final step can be carried out.

third step, the decimal data of the for loop e determines the first 10-digit prime number.

Straight to the point, throw the source code directly first.

Specific ideas: first use the requests library to obtain e decimal place data, and then transfer it to a file for reading line by line, the for loop reads each decimal place data line by line, performs slicing operation, and organizes it into 10-digit integers required for the proof. Get an ordered list with a total number of 49991, and then use the prime number determination function to determine these 10-bit integers one by one, and finally get the answer - 7427466391.

import requests
import re

response = requests.get('https://oeis.org/A001113/b001113.txt')

# Save sequence to a file for later use
out_file = open('digits_of_e.txt', 'w')
print(response.text, file=out_file)

queue = []

container = ''
counter = 0  
in_file = open('digits_of_e.txt', 'r')
list_in_file = list(in_file)
for index, line in enumerate(list_in_file):
  segments = list_in_file[index:index+10]
  # get lines at a batch of 10 lines
  for segment in segments:
    matchObj = re.match(r'([\d]*) (\d).*', segment, re.I)
    counter += 1
    if counter <= 10:
      container += matchObj.group(2) if matchObj != None else ''
    else:
      counter = 1
      if len(container) == 10:
        queue.append(container)
      container = matchObj.group(2) if matchObj != None else ''
in_file.close()

print(len(queue)) # 49991 indeed

def isPrime(n: int) -> bool:
  # Prime number definition version:
  '''
  if n <= 1:
    return False
  i = 2
  # Make use of symmetry. For example, 2*3=6, 3*2=6
  while i * i < n:
    if n % i == 0:
      return False
    i += 1
  return True
  '''
  # Distribution pattern of prime number version:
  if n <= 1:
    return False
  if n <= 3:
    return True
  # For case of 2(3x + 1), 3(2x + 1), 2(3x + 2)
  if n % 2 == 0 or n % 3 == 0:
    return False
  # For case of the multiplication of prime numbers
  i = 5
  while i * i < n:
    if n % i == 0 or n % (i + 2) == 0:
      return False
    i += 6
  return True

result = None
for num in queue:
  if isPrime(int(num)):
    print(num)
    result = num
    break

print(result == '7427466391')
print(isPrime(7427466391))

operation result:

bingo!

image-20220115031650305

Finish

After the proof question is answered, we have to take a ritual and visit this website - 7427466391.com.

The result is a 502 error...

image-20220115162556092

Okay, it seems that this site has been abandoned long ago, after all, this highway ad is also a prank by Google in 2004.


Finally, the source code is sorted into a Kaggle Notebook version. Welcome to check!

First10DigitPrimeFoundInConsecutiveDigitsOfE | Kaggle

Summary of References

  1. The Top of the Tide (4th Edition) by Mr. Wu Jun P44
  2. Irrational number e Wikipedia
  3. A001113 page OEIS site
  4. Table of 50000 digits of e labeled from 1 to 50000
  5. Prime Number Judgment Algorithm
  6. PyCrypto cryptography library source code analysis (1) random number and large prime number generation
  7. What Google’s Genius Billboard From 2004 Can Teach Us About Solving Problems

冒泡的马树
194 声望14 粉丝

曾痴迷于赛博朋克世界的代码玩家一枚,