Prime number. In a natural number greater than 1, except for 1 and the integer itself, it cannot be divisible by other natural numbers. In other words, only the natural numbers of two positive factors (1 and itself) are prime numbers. A number larger than 1 but not a prime number is called a union number. 1 and 0 are both non-prime numbers and non-composite numbers. The sum is obtained by multiplying multiple prime numbers. Therefore, the prime number is the basis of the Union, and there is no combination without the prime number.
[1] General Method
A prime number is a natural number that cannot be divisible by any other number except 1 and itself. Since we cannot find a general formula to represent all prime numbers, prime numbers have always been unknown to mathematicians. Like the famous golden Bach conjecture and the twin prime conjecture, I have not known how many excellent mathematicians have been attracted in the world for centuries. Despite painstaking research and painstaking efforts, it is still unknown.
With the power of computers, people have found all prime numbers within 2216091.
There are many methods to evaluate prime numbers. The simplest method is to evaluate a prime number based on its definition. For a natural number N, remove N from each natural number greater than 1 and less than N. If n is not divided, n is the prime number; otherwise, n is the Union number.
However, if you use the prime number definition method to compile a computer program, its efficiency must be very low, and many of them deserve improvement.
First, for a natural number N, as long as it can be divisible by a non-1 Non-its own number, it is certainly not a prime number, so no
Other numbers must be removed.
Second, for N, you only need to remove the prime number less than N. For example, if N can be divisible by 15, the actual
3 and 5 can be divisible. If n cannot be divisible by 3 and 5, N will never be divisible by 15.
Third, for N, you do not need to remove all prime numbers from 2 to N 1. You only need to remove all prime numbers less than or equal to √ N (root number N. This can be proved by the reverse proof:
If n is a combination, there must be integers D1 and D2 greater than 1 and less than N, so that n = D1 × d2.
If D1 and D2 are greater than √ N, there are: N = D1 × D2> √ n × √ n = n.
This is not possible. Therefore, one of D1 and D2 must be less than or equal to √ n.
Based on the above analysis, the design algorithm is as follows:
(1) Use the method of Division n one by one to obtain all prime numbers within 100.
(2) Calculate the prime number within 100 by division of all prime numbers within 10000 one by one.
First, store, and in a [1], a [2], a [3], and a [4], and then obtain each prime number, as long as it is no greater than 100, it is stored in one unit in array a in sequence. When we calculate the prime number between 100-10000, we can use the prime number of a [1]-A [2] to try to divide N in sequence. The prime number in this range can be printed without being saved.
[2] Here we will mainly explain the erlatosse screening method.:
A Brief Introduction to the erradose screening method. Herados is an ancient Greek mathematician. When looking for prime numbers, he adopted a different method: first put the numbers of 2-N into a table, and then draw a circle on the top of 2, then draw the other multiples of 2. The first number that is neither circled nor excluded is 3. Draw the circle and then draw the other multiples of 3; the first number that is neither circled nor excluded is 5. Draw the circle and draw other multiples of 5 ...... And so on until all numbers less than or equal to N are circled or crossed. At this time, the number of circles and undrawn values in the table is exactly the prime number smaller than N.
This is like a sieve, which leaves the number that meets the conditions behind and filters out the number that does not meet the conditions. As this method was first invented by heradosse, future generations will call this method the heradosse screening method.
In the computer, the screening method can be implemented by setting the array unit to zero. Specifically: First open an array: A [I], I = 1, 2, 3 ,..., At the same time, make all array elements equal to the subscript value, that is, a [I] = I. When I is not a prime number, make a [I] = 0. When outputting results, you only need to judge whether a [I] is equal to zero. If a [I] = 0, I = I + 1 and check the next a [I].
Screening is one of the common algorithms in computer programming.
For C ++ code reference (calculate a prime number smaller than 2000 ):
#include "stdafx.h"#include <iostream>using namespace std;#define N 2000int _tmain(int argc, _TCHAR* argv[]){int num[N];for (int i = 0; i < N; i++){num[i] = i;}for (int j = 2; j < N; j++){if(0 != num[j]){for (int k = 2; k*j < N; k++){num[k*j] = 0;}}}for (int n = 0; n < N; n++){if(0 != num[n]){cout<<" "<<num[n];}}cout<<endl;return 0;}
[3] calculate the prime number using the 6N ± 1 method.
Any natural number can always be expressed as one of the following forms:
6N, 6N + 1, 6N + 2, 6N + 3, 6N + 4, 6N + 5 (n = 0, 1, 2 ,...)
Obviously, when n is ≥1, 6N, 6N + 2, 6N + 3, 6N + 4 are not prime numbers, only the natural numbers such as 6N + 1 and 6N + 5 may be prime numbers. Therefore, all prime numbers except 2 and 3 can be expressed in the form of 6N ± 1 (n is a natural number ).
Based on the above analysis, we can construct another sieve to filter the natural numbers such as 6 N ± 1, which can greatly reduce the number of screening times, this further improves the program running efficiency and speed.
Conjecture related to prime numbers
Godebach Conjecture
Goldbach Conjecture can be roughly divided into two conjecture types "): 1. Each even number not less than 6 can be expressed as the sum of two odd prime numbers; 2. Each odd number not less than 9 can be expressed as the sum of three odd prime numbers.
Riman Conjecture
This is a difficult problem that has plagued the field of mathematics for many years. It was first proposed by German mathematician bonhad Riem. So far, no one has provided a convincing and reasonable proof. That is, how to prove that "all the meanings of the equations of prime numbers are in a straight line ".
The prime number month in the law of this prime number goes through an integer. "The solution of all meanings of the equation of prime number is in a straight line" is a sphere prime number distribution.
Twin prime number conjecture
In 1849, polenak proposed the conjecture of twin primes, that is, an infinite number of twins.
The "twin prime number" in the conjecture refers to a pair of prime numbers with a difference of 2. For example, values 3, 5, 7, 11, 10016959, and are twin prime numbers.
10016957 and 10016959 are the twins of [18 ± 1] In The Middle Of The 333,899th-digit prime number month.
Prime Number month positioning twin prime number occurrence location:
Occurrence location of the first prime number month's twin prime number: [T-1] * 30 + [[4 ± 1] [6 ± 1] [12 ± 1] [18 ± 1] [30 ± 1] T = 1
Where the twins of other prime numbers occur: [T-1] * 30 + [[0 ± 1] [12 ± 1] [18 ± 1] [30 ± 1] t = n is a natural number representing the prime number month
Reprinted from multiple locations. You cannot check the source address. Please forgive me.