Message Boards Message Boards

4
|
5612 Views
|
2 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Search for prime numbers greater than 5

Posted 5 years ago

Prime numbers greater than $5$ can be classified into two types. $n$ is a positive integer $(n = 1, 2, 3...)$, a $(6n-1)$ type prime number and a $(6n + 1)$ type prime number. These two types of prime numbers can be determined by the following two equations $(1{\rm a})$ and $(1{\rm b})$, respectively.

$$\begin{equation} \;\,\quad (6n-1)\,{\rm type\ prime}? \left \{ \begin{array}{l} n=6s_1^2+(6s_1-1)(m_1-1) \\ n=6s_2^2+6s_2+1+(6s_2+1)(m_2-1) \end{array} \right.\tag{1a}\\ \end{equation} $$

$$\begin{equation} (6n+1)\,{\rm type\ prime}? \left \{ \begin{array}{l} n=6s_3^2-2s_3+(6s_3-1)(m_3-1) \\ n=6s_4^2+2s_4+(6s_4+1)(m_4-1)\\ \end{array} \right.\tag{1b}\\ \end{equation} $$

$$\begin{equation} n=1,2,3\cdots \end{equation} $$

Give any positive integer for $n$ in equation ( $1{\rm a}$). Then let $n$ be written as $n_m$ when $s$ and $m$ do not have integer solutions. Similarly, $n$ is given to equation ( $1{\rm b}$), and $n$ is expressed as $n_p$ when $s$ and $m$ do not have integer solutions. A prime number is born from $n_m$ and $n_p$ according to equation ( $2$).

$$\begin{eqnarray} (6n-1)\text{ type prime}&=&6n_m-1\tag{2a} \\ (6n+1)\text{ type prime}&=&6n_p+1\tag{2b} \\ \end{eqnarray}$$

$$\begin{equation}n_m\ {\rm and}{\text{ }}n_p: {\rm In\ Equation\ (1),{\it n}\ when\ there\ is\ no\ integer\ solution\ for\ {\it s}\ and\ {\it m}.}\end{equation}$$

A program for searching for prime numbers by inputting $n$ is shown below. Searches the range from $n$ to $(n + 100)$, and if there is a prime number in the interval, it shows one set of two types of prime numbers. If there is a prime number on one side, this is indicated. If there are no prime numbers in this section, that effect is displayed. If you want to proceed with the calculation with or without a prime number, indicate $n$ to start next.

n = 1;

Clear[nm, np, ndm, ndp];
If[n > 0 && IntegerQ[n],
  Do[{dat1 = 
     FindInstance[
      6*s1^2 + (6*s1 - 1)*(m1 - 1) == n && 0 < s1 && 0 < m1, {s1, m1},
       Integers];
    dat2 = 
     FindInstance[
      6*s2^2 + 6*s2 + 1 + (6*s2 + 1)*(m2 - 1) == n && 0 < s2 && 
       0 < m2, {s2, m2}, Integers]};

   If[dat1 == {} && dat2 == {}, nm = n, 
    nm = "(-_-;) There is no solution in this section."]; 
   If[dat1 == {} && dat2 == {}, Break[]], {n, n, n + 100}];
  If[IntegerQ[nm], ndm = nm, ndm = 0];

  Do[{dat3 = 
     FindInstance[
      6*s3^2 - 2*s3 + (6*s3 - 1)*(m3 - 1) == n && 0 < s3 && 
       0 < m3, {s3, m3}, Integers];
    dat4 = 
     FindInstance[
      6*s4^2 + 2*s4 + (6*s4 + 1)*(m4 - 1) == n && 0 < s4 && 
       0 < m4, {s4, m4}, Integers]};

   If[dat3 == {} && dat4 == {}, np = n, 
    np = "(-_-;) There is no solution in this section."]; 
   If[dat3 == {} && dat4 == {}, Break[]], {n, n, n + 100}];
  If[IntegerQ[np], ndp = np, ndp = 0];

  Print["====== The calculation results are shown below. ======"];

  Print["nm= ", nm];
  Print["np= ", np];

  If[ndm > 0, Print["(6n-1)Type Prime= ", 6*nm - 1], 
   Print["(6*n-1)Type Prime= (-_-;)There are no Prime numbers in this \
interval,at (n)~(n+100)."]];
  If[ndp > 0, Print["(6n+1)Type Prime= ", 6*np + 1], 
   Print["(6*n+1)Type Prime= (;-_-)There are no Prime numbers in this \
interval,at (n)~(n+100)."]];

  Print["PrimeQ= ", {PrimeQ[6*nm - 1], PrimeQ[6*np + 1]}];

  If[dat1 == {} && dat2 == {} && dat3 == {} && dat4 == {} && nm == np,
    Print["(^_^)This is a Twin Prime number."]];

  If[ndm > 0 && ndp > 0, 
   Print["If you want to find the next Prime, start with n= ", 
    Min[ndm, ndp] + 1]];
  If[ndm == 0 && ndp == 0, 
   Print["If you want to continue, start with n= ", n + 101]];
  If[Or[ndm > 0 && ndp == 0, ndm == 0 && ndp > 0], 
   Print["If you want to find the next Prime, start with n= ", 
    Max[ndm, ndp] + 1]], 
  Print["***** ! Please enter a positive integer. *****"]];

The calculation result is displayed as follows. For example, when $n = 1$ is entered.

====== The calculation results are shown below. ======
nm= 1
np= 1
(6n-1)Type Prime= 5
(6n+1)Type Prime= 7
PrimeQ= {True,True}
(^_^)This is a Twin Prime number.
If you want to find the next Prime, start with n= 2

Indicates $n_m$ and $n_p$ selected in the first and second lines. In this example, $n_m = 1$ and $n_p = 1$. Next, the prime number of $(6n-1)$ type and the prime number of $(6n + 1)$ type are shown. "PrimeQ" confirms that this number is indeed a prime number. If this prime number is a twin prime, this is indicated. Finally, when searching for the next prime number, the integer to be input to $n$ is shown.

The following table shows an example of the results calculated sequentially from $n = 1$ in this way.

$$\begin{array}{ccc} n_m\, {\rm and}\,\ n_p & \text{}{(6n-1)\rm\ type\ prime}\ &{(6n+1)\ {\rm type}\ {\rm prime}} \\ 1 & 5 &7\\ 2 & 11&13 \\ 3 & 17&19 \\ 4 & 23&- \\ 5 & 29&31 \\ 6 & -&37 \\ 7 & 41&43 \\ 8 & 47&- \\ 9 & 53&- \\ 10 & 59&61 \\ 11 & -&67 \\ 12 & 71&73 \\ 13 & -&79 \\ 14 & 83&- \\ 15 & 89&- \\ 16 & -&97 \\ 17 & 101&103 \\ 18 & 107&109 \\ 19 & 113&- \\ 21 & -&127 \\ 22 & 131&- \\ 23 & 137&139 \\ 25 & 149&151 \\ 26 & -&157 \\ 27 & -&163 \\ 28 & 167&- \\ 29 & 173&- \\ 30 & 179&181 \\ 32 & 191&193 \\ 33 & 197&199 \\ 35 & -&211 \\ 37 & -&223 \\ 38 & 227&229 \\ 39 & 233&- \\ 40 & 239&241 \\ 42 & 251&- \\ 43 & 257&- \\ 44 & 263&- \\ 45 & 269&271 \\ 46 & -&277 \\ 47 & 281&283 \\ 49 & 293&- \\ 51 & -&307 \\ 52 & 311&313 \\ \text{Omitted below} & \text{Omitted below} &\text{Omitted below} \end{array}$$

Try entering a slightly larger number to try it out. Let's take $n = 27182818284590452353602874713526624977572470937000$. This is somehow familiar. That's right. The base of natural logarithm (Napier's constant) is displayed in 50 digits and the decimal point is removed. The calculation result is as follows.

====== The calculation results are shown below. ======
nm= 27182818284590452353602874713526624977572470937000
np= 27182818284590452353602874713526624977572470937028
(6n-1)Type Prime= 163096909707542714121617248281159749865434825621999
(6n+1)Type Prime= 163096909707542714121617248281159749865434825622169
PrimeQ= {True,True}
If you want to find the next Prime, start with n= 27182818284590452353602874713526624977572470937001

In this way, the following two prime numbers were obtained.

$(6n-1)$ type prime $= 163096909707542714121617248281159749865434825621999$ $(6n + 1)$ type prime $= 163096909707542714121617248281159749865434825622169$

In this example, my computer took about 46 seconds to calculate. Some readers may write faster programs.

POSTED BY: Koichi Ohno
2 Replies
Posted 5 years ago

William-san

Thank you for your comments.

The program that you have shown kindly can be a great help.

I didn't know "trial factorization", so I will study from now on.

After all, there are so many functions in Mathematica that only a part of them are used. It is a pleasure to open my sight through the readers of the Wolfram Community.

(-san is a title in Japanese)

POSTED BY: Koichi Ohno
Posted 5 years ago

I'd like to point out that solving these equations is equivalent to trial factorization of the number $6n\pm1$ under consideration. Take the first of the four equations and rewrite it in terms of say $z=6n-1$:

z = 6n-1 /. n->(6s^2 + (6s-1)(m-1) ) // Simplify

(-1 + 6 s) (-5 + 6 m + 6 s)

The second equation picks out the complementary set of possible factors:

z = 6n-1 /. n->(6s^2 +6s + 1 + (6s+1)(m-1) ) // Simplify

(1 + 6 s) (-1 + 6 m + 6 s)

For example, the first composite $6n-1$ for $n=6$ ( $z=35$) has a solution to $(1a(1))$ of ${s=1,m=1}$; this corresponds to the factors $6s-1=5$ and $6s+6m-5=7$.

We can similarly manipulate the equations $(1b)$ to find their algebraic factorizations for any $z'=6n+1$.

The functions PrimeQ[] and NextPrime[] will be faster than solving these equations (i.e., trial factorization).

POSTED BY: William Isaacs
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract