From prime to prime by squaring the digits

191 Views Asked by At

I took prime $131$, squared digits of it and wrote them in natural order as they appear, from left to right, and obtained $191$, then I obtained $1811$ by the same procedure, and then $16411$ and then $1361611$, and $131,191,1811,16411$ are primes and $1361611$ is not.

To illustrate how to arrive at the next number in sequence from previous one, take, for example, $16411$.

We have: $1^2=1$ and $6^2=36$ and $4^2=16$ and $1^2=1$ and $1^2=1$ so we obtain $1361611$ from $16411$.

Can we generate in this way as large a number of different (to avoid loops like one that starts with $11$) primes as we want? Or there is/are some law/laws that do not allow that?

1

There are 1 best solutions below

10
On

Please do not downvote !

I just want to show my program and the numbers upto $150\cdot 10^6$ giving $5$ or $6$ primes. I hope that someone can verify whether my program is actually correct.

? t=0;m=0;while(t<7,m=nextprime(m+1);gef=0;t=0;n=m;while((isprime(n,2)==1)*(gef=
=0),d=digits(n);s=0;for(j=1,length(d),if(d[j]>0,s=s*10^length(digits(d[j]^2))+d[
j]^2);if(d[j]==0,s=s*10));if(n==s,gef=1);n=s;t=t+1);if(t>=5,print(m,"  ",t)));pr
int(m,"  ",t)
2111  5
2179223  5
3012137  5
5103611  5
5320309  5
6018713  5
6033593  5
6096907  5
7868621  5
8126617  5
10033109  5
11119001  5
12139483  5
12815137  6
13622461  5
18901391  5
18991061  5
21806593  5
22024993  5
24414217  5
27073433  5
30652483  5
37102529  5
38024237  5
38318381  5
42991061  5
44402023  5
47240177  5
48413147  5
50507983  5
56415659  5
57493621  5
70284323  5
70882139  5
71164913  5
81266123  5
82376953  5
84304607  5
88399933  5
90194861  5
97372019  5
100544033  5
107802001  5
110006453  5
110084281  5
111944939  5
114471263  6
115405699  5
115629091  5
118326457  5
120451927  5
124656913  5
126060271  5
126651227  5
127991333  5
128151323  6
130147313  5
139151029  5
141296509  5
143451823  5
144418661  6
152451113  5
  ***   at top-level: ...+1);gef=0;t=0;n=m;while((isprime(n,2)==1)*(ge
  ***                                             ^--------------------
  *** isprime: user interrupt after 26min, 11,531 ms
  ***   Break loop: <Return> to continue; 'break' to go back to GP prompt
break>
?