How to resolve the algorithm Prime conspiracy step by step in the PARI/GP programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Prime conspiracy step by step in the PARI/GP programming language

Table of Contents

Problem Statement

A recent discovery, quoted from   Quantamagazine   (March 13, 2016): and

The task is to check this assertion, modulo 10. Lets call    i -> j   a transition if    i   is the last decimal digit of a prime, and    j   the last decimal digit of the following prime.

Considering the first one million primes.   Count, for any pair of successive primes, the number of transitions    i -> j   and print them along with their relative frequency, sorted by    i . You can see that, for a given    i ,   frequencies are not evenly distributed.

(Modulo 10),   primes whose last digit is   9   "prefer"   the digit   1   to the digit   9,   as its following prime.

Do the same for one hundred million primes.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Prime conspiracy step by step in the PARI/GP programming language

Source code in the pari/gp programming language

conspiracy(maxx)={
print("primes considered= ",maxx);
x=matrix(9,9);cnt=0;p=2;q=2%10;
while(cnt<=maxx,
cnt+=1;
m=q;
p=nextprime(p+1);
q= p%10;
x[m,q]+=1);  
print (2," to ",3, " count: ",x[2,3],"  freq ", 100./cnt,"  %" );
forstep(i=1,9,2,
forstep(j=1,9,2,
if( x[i,j]<1,continue);
print (i," to ",j, " count: ",x[i,j],"  freq ", 100.* x[i,j]/cnt,"  %" )));
print ("total transitions= ",cnt);
print(p);
}

primes considered= 1000000
2 to 3 count: 1  freq 0.000100  %
1 to 1 count: 42853  freq 4.29  %
1 to 3 count: 77475  freq 7.75  %
1 to 5 count: 0  freq 0  %
1 to 7 count: 79453  freq 7.95  %
1 to 9 count: 50153  freq 5.02  %
3 to 1 count: 58255  freq 5.83  %
3 to 3 count: 39668  freq 3.97  %
3 to 5 count: 1  freq 0.000100  %
3 to 7 count: 72828  freq 7.28  %
3 to 9 count: 79358  freq 7.94  %
5 to 1 count: 0  freq 0  %
5 to 3 count: 0  freq 0  %
5 to 5 count: 0  freq 0  %
5 to 7 count: 1  freq 0.000100  %
5 to 9 count: 0  freq 0  %
7 to 1 count: 64230  freq 6.42  %
7 to 3 count: 68595  freq 6.86  %
7 to 5 count: 0  freq 0  %
7 to 7 count: 39604  freq 3.96  %
7 to 9 count: 77586  freq 7.76  %
9 to 1 count: 84596  freq 8.46  %
9 to 3 count: 64371  freq 6.44  %
9 to 5 count: 0  freq 0  %
9 to 7 count: 58130  freq 5.81  %
9 to 9 count: 42843  freq 4.28  %
total transitions= 1000001
15485917
time = 5,016 ms.

  

You may also check:How to resolve the algorithm Smith numbers step by step in the Quackery programming language
You may also check:How to resolve the algorithm Reverse a string step by step in the REBOL programming language
You may also check:How to resolve the algorithm Exponentiation order step by step in the D programming language
You may also check:How to resolve the algorithm Floyd's triangle step by step in the 360 Assembly programming language
You may also check:How to resolve the algorithm Jewels and stones step by step in the Modula-2 programming language