Number theory and its application--prime problem

Source: Internet
Author: User

Mathematics is the Queen of Science, and number theory is the Queen of Mathematics--Gauss.
Then I continued the tail of the dog--the prime number is the Queen of number theory.

Talking about prime numbers, can involve a lot of mathematical history of the daring work legend, such as in the last few days to see the "Remove the wine, how people enjoy life" problem, in an answer to a few big scientists, including a favorite prime mathematician, choose the monthly prime days and wife cohabitation, one months just beginning okay , but the more the month-end prime spacing becomes larger, the days of cohabitation become less.

In the prime of this small place, there are many well-known speculation, can be proven to some really very, very strong, because today's world is circulating such a legend, set up seven world math puzzles, you can summon the dragon, to help you achieve a desire.
Far away, here are a few guesses about primes first.

Twin prime conjecture: There are infinitely many prime pairs of shapes such as p,p+2.
1966 Chen Jingrun The existence of an infinite number of pairs of twin prime numbers with complex sieve method, now looking for twin primes has become a fun contest, the largest twin prime pair is 33218925.2^169690 +1, 33218925.2^169690-1. The Chinese mathematician Zhang Yitang a remarkable achievement in this respect.

Goldbach conjecture: Each positive even number greater than 2 can be written as a sum of two primes.
This conjecture is given in the 1742 Goldbach letter to Euler, which has now verified that all even numbers less than 4 * 10^14 satisfy this conjecture.

N^2 + 1 Conjecture: There is an infinite number of primes, such as n^2 + 1, where n is a positive integer.

People are not only fascinated by the form of prime numbers, but also are keen to explore the distribution of prime numbers. Here we draw the prime number theorem--set π (x) to be less than integer x number of elements, then with the increase of x, there is π (x) = X/lnx. Due to time, this is not the case for the proof process.

So based on this theorem, we can solve a practical problem. (Problem Source:nufu 117)


   for this problem, we obviously can't directly calculate the amount of data, so we need to use our prime number theorem. However, it is important to note here that the number of bits is required, and that n here is 10^n, which is different from the X in the theorem.
  In addition, to find the number of digits of an integer x, there is the formula LG (x) + 1, then LG (10^N/LN (10^n)) + 1 is the subject of the request, in a simple simplification, programming implementation can be. The
 
  Reference code is as follows.

#include <iostream>#include<math.h>usingnamespace  std; int Main () {    int  n;     Double 2.71828 ;      while (Cin >> N)    {          double m = (N-LOG10 (n)-log10 (log ()));           int 1 << Endl;    }}



In addition to the distribution of prime numbers, it is also a fundamental problem to determine whether a number is prime.
For the determination of prime numbers, the first thing we think of is a violent and exhaustive act according to its definition. That is, given the number n, we traverse [1,n] integers, judging by the factors that can be divisible.
But we find that the n factor is in pairs, that is, n = i * j, when we traverse to I, we actually find a factor to--i,j, so when we traverse J, we revisit the factor to--i,j, which creates a waste of time. From the axis, these pairs of factors are "paired", and this symmetry point is obviously sqrt (n). So we can optimize the method of judging the prime number above and traverse [1,sqrt (N)].
But there are more efficient algorithms--the Erato-color sieve method. It doesn't need proof, it's easy to understand. Is that we assume that all integers on [1,n] are prime, and then iterate backwards from 2, and if the current I is a prime number, then enter the loop, and the loop is filtered in multiples of all I in [1,n], labeled composite. Compared to the first two methods, this method is obviously much more efficient.
The upper bound of the above method of processing data is incremented sequentially, but if a data to practice the third sieve method can not handle it? Then we have the flexibility to combine the second common sieve and the third efficient sieve method. Given a very large integer n, we traverse the integers between [1,sqrt (N)], where the second common sieve is used. But we only need to traverse the prime of this interval, because if it is composite, it must have a smaller factor, which will be traversed before, thus causing the time wasted by repeated traversal. And how to find the number of the number on this interval, relying on the funny Erato color-sieve method.
As long as the principle of the sieve itself is fully understood, the implementation of the programming is simple simulation, it is easy to achieve.

Then let's combine a topic to implement the following code specifically. (Problem Source:nefu 109)

You can see that this is the very big problem of handling data that we are referring to, and we need to combine the two screens together.
The reference code is as follows.

#include <stdio.h>#include<iostream>#include<cmath>#include<cstring>Const intN =50001;using namespacestd;BOOLIsprime[n];intPrime[n],nprime;voidDoprime ()//Erato Screening Method{     Long LongI, J; Nprime=0; memset (IsPrime,true,sizeof(IsPrime)); isprime[1] =0;  for(i =2; I < n;i++)       {              if(Isprime[i]) {prime[++nprime] =i;  for(j = I+i;j < N; J + =i) {prime[j]=false; }              }       }}BOOLIspintN//Basic Sieve Method{     intI, k = (int) sqrt (Double(n));  for(i =1;p Rime[i] <= k;i++)             if(N%prime[i] = =0)                return 0; return 1;}intMain () {doprime (); Long LongN;  while(Cin >>N) {if(n = =1) {cout<<"NO"<<Endl; Continue; }        if(ISP (n)) cout <<"YES"<<Endl; Elsecout <<"NO"<<Endl; }     return 0;}


From the point of view of the prime number of the analysis of the whole field, mathematicians found a lot of laws, through the induction method we are very easy to know that n can represent the product of prime, that is, n = p1*p2*p3......pn, where the pi is a prime number. Here we give the basic theorem of arithmetic.

Theorem: Each positive integer greater than 1 N, can be uniquely written as the product of a prime number: N = p1^a1 * P2^A2 * ... * pk^ak. Based on this formula, we can get a lot of useful properties, which we will introduce in turn later in the article.

The power of the prime number p in the decomposition of the attribute 1:n! factor is: [n/p] + [n/p^2] + [n/p^3] ... In this case, due to time and the author's ability reasons, we would not mention its detailed proof. Instead, you learn to apply it by practicing it first.

So let's look at a question that needs to be applied to this nature. (Problem Source:nefu 118)

We look at this problem, obviously we directly find the value of n! and then%10 calculate the violence method is unreasonable, we have to skillfully use the nature we have just learned. Because this nature, like this one, contains n!. We n! this number from the point of view of the prime theorem, which can be written as the product of multiple primes, namely n! = P1^A1 * P2^A2 * P3^a3 ... * pm ^ am form. So at this point we want to know how many 0 at the end of this number, conversion, that is, by the n! as the product of the form, and then found 10 of the power of this factor, and 10 can continue to split into two primes--2 and 5, namely n! = 2^a * 5^b *......,min (A, B) the answer to this question. It is easy to see, n! this number, split into prime multiplication form, the power of 2 is certainly greater than the power of 5, so here we just find the power of 5, can be used as the answer to this question.

With this layer of mathematical analysis, we can apply it to the properties above. And in the implementation of programming, it is only simple design through the link to solve.

The reference code is as follows.

#include <cstdlib>#include<iostream>using namespacestd;intMain () {intn,m,t,sum,five; CIN>>N;  while(n--) {cin>>m; T=m; Five=5; Sum=0;  while(Five <=t) {sum= sum + t/five; Five= Five *5; } cout<< sum <<Endl; }    return 0;}

Reference system: "Number theory and its application" Chen Yu

                                                                                                                                                                                            --< not finished >

Number theory and its application--prime problem

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.