Have you ever heard of Goldbach's conjecture? It is indeed one of the three major modern mathematics problems in the world (48)

Hello children, hello big friends!

I'm Cat Girl, a primary school student who fell in love with Python programming.

Learn Python with Cat Girl and learn programming together.

today's theme

What is Goldbach's conjecture?

How to verify that the number within 100 is in line with Goldbach's conjecture?

Goldbach Conjecture

what is a prime number

A prime number (Prime Number) refers to a positive integer that can only be divisible by 1 and itself, that is, a natural number that has no other factors except 1 and itself. For example, 2, 3, 5, 7, 11, etc. are all prime numbers.

The opposite of a prime number is a composite number, which refers to a natural number that has factors other than 1 and itself. For example, 4, 6, 8, 9, 10, etc. are composite numbers.

Prime numbers play an important role in mathematics, and they are synonymous with prime numbers.

A prime number is a positive integer that can only be divisible by 1 and itself, while a prime number emphasizes the fact that it can only be divisible by 1 and itself.

Prime numbers are widely used in cryptography, computer science, statistics and other fields.

Goldbach and Euler

Communication between Goldbach and Euler took place by letter.

On June 7, 1742, Goldbach proposed two bold conjectures in a letter to Euler:

Any odd number greater than 5 can be expressed as the sum of three prime numbers.

In his reply, Euler stated that he was convinced that these two conjectures of Goldbach were correct theorems, but Euler could not give a proof at that time.

Goldbach's conjecture has since become one of the most famous unsolved problems in the field of number theory.

There are many versions of Goldbach's conjecture, the most famous of which are the following two:

  1. Even number version: Any even number not less than 6 can be expressed as the sum of two prime numbers.
  2. For example
  3. 4 = 2 + 2,
  4. 6 = 3 + 3
  5. 8 = 3 + 5
  6. 10 = 3 + 7
  7. The even number version is also called the Euler version, that is, any even number greater than 2 can be written as the sum of two prime numbers, also known as "Strong Goldbach's conjecture" or "Goldbach's conjecture about even numbers".
  8. Odd version: Any odd number not less than 9 can be expressed as the sum of three prime numbers.
  9. For example,
  10. 9 = 2 + 2 + 5,
  11. 11 = 2 + 3 + 6,
  12. 13 = 2 + 3 + 8,
  13. 15 = 2 + 5 + 8,
  14. The odd version is also known as "weak Goldbach's conjecture" or "Goldbach's conjecture about odd numbers".

In May 2013, Harold Hoofgot, a researcher at the Ecole Normale Supérieure de Paris, published two papers announcing the complete proof of the weak Goldbach conjecture.

Python validates numbers within 100

How to check whether a number is prime?

import math
# 判断数字是否为素数
def isPrime(n):
    if n <= 1:
        return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True

How to verify that all even numbers between [2,100] conform to Goldbach's conjecture?

import math


# 判断数字是否为素数
def isPrime(n):
    if n <= 1:
        return False
    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False
    return True


#验证大于2的偶数可以分解为两个质数之和
def goldbach(T):
# T为列表,第一个元素为区间起点,第二个元素为区间终点
    S = T[0]
    E = T[1]
    sample=[]   #用于返回样例
    print('-----------')
    if S < 4:   #若不是大于2的偶数
        S = 4   #设为大于2的最小偶数
    if S % 2 == 1:      #除2余数为1的是奇数
        S += 1          #奇数+1为偶数
    for i in range(S, E + 1, 2):    #遍历区间内所有偶数
        isGoldbach = False
        for j in range(i // 2 + 1): # 表示成两个素数的和,其中一个不大于1/2
            if isPrime(j):
                k = i - j
                if isPrime(k):
                    isGoldbach = True
                    sample.append((i,j,k))
                    break
        if not isGoldbach:
            #如果打印这句话表示算法失败或欧拉错了
            sample.append('哥德巴赫猜想失败!')
            break
    return sample


if __name__ == '__main__':
    sample = goldbach([2,100])
    print(sample)

Well, let's learn this today!

If you encounter any problems, let's communicate and solve them together.

I'm Cat Girl, see you next time!

Guess you like

Origin blog.csdn.net/parasoft/article/details/130894744