Talk about how to detect prime numbers

Source: Internet
Author: User

Recently saw a rather interesting news, said a freshman in Peking University, to prime numbers as the standard choice mobile phone number, by the vast number of netizens worship. In fact, the detection algorithm is very interesting, and will involve number theory, probability algorithm and many other content, has always felt that the prime detection algorithm is a good understanding of the probability algorithm of the entrance. This article and everyone simple talk about how to determine a number is prime. Prime Number definition of Prime number

The primes are defined like this:

An integer greater than 1, or a prime number (also known as a prime number) if it cannot be divisible by a positive integer other than 1 and itself.

The definitions associated with primes are also composite:

An integer greater than 1, or composite if it is not a prime number. which can divide the number of positive integers called approximate, not equal to 1 is not equal to the composite itself is called non-trivial approximate.

Note that 1 is neither prime nor composite.

For a few examples:

2 is a prime number because no other positive integer except 1 and 2 can be divisible by 2.

3 is also a prime number.

4 is not a prime number because 2 can be divisible by 4.

11 is a prime number, except 1 and 11 without a positive integer to divide it.

15 is not a prime, 3 and 5 can be divisible by 15. properties of prime numbers

Prime numbers have some interesting properties, few of which are shown below.

There are infinitely many primes.

Set f (n) to the function defined on the set of integers greater than 1, so that the value of f (n) is the number of primes not greater than N, then:

Limn→∞f (n) n/lnn=1 limn→∞f (n) n/ln n=1

This function is called the prime distribution function, which reflects the distribution law of prime numbers. In other words, it can be thought that the first n positive integers greater than 1, the number of primes is approximately N/LNN n/ln N. Detection Prime

The so-called prime detection, is given any one greater than 1 integer, to determine whether this number is prime. Factor Detection Method

The most intuitive prime detection algorithm is the factor detection method. Plainly, it is from 2 to n-1 one by one to try to see if we can divide N, if there is divisible (find a factor), then the output is not prime, otherwise, n is considered prime. Of course, there is no need to test to n-1, as long as the n√n is good, for the following reasons:

Set N=AXB N=AXB, and A, B are N of the non-trivial approximate, obviously a>n√a>n and b>n√b>n can not be set up at the same time, because at the same time A*b will be greater than N, so, if n exists non-trivial approximate, then at least one less than equals

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.