c++ - Find a prime number? -


To know that N is a prime number, we should only assign all numbers or at least sqrt (N) Need to look for Why is it like this? I am trying to understand a reason behind this.

If there is a positive integer that is divisible by two positive integers, 1 and n Because a number separator can not be greater than that number, this is a simple systemic examination:

  • If an integer N, more than 1, any integer category [ 2, N-1] , then N is the principal. Otherwise, N is not the principal.

However, it may be best to revise this test to speed up. So let us check.

Note that N's separators are in pairs. If N is divisible by a number M, then it is also divided by N / M. For example, 12 divisble 6 is also 2. In addition, if M & gt; = Sqrt (N) , then N / M .

This means that if a number is less than or equal to the division of sqrt (n), then divide large numbers (excluding n 1 and n itself) from sqrt (n) Otherwise, there is a contradiction.

Then we have a better test:

  • If an integer N is greater than 1, then the division is not divided by any integer [2] , Sqrt (n)] , then N is the principal, otherwise the N is not the principal.

If you consider the logic above, you should see that a number passing through this test also passes the test, and a number that fails, this test Also fails the first test so tests are similar.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -