# From prime to prime by squaring the digits

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?

• There may be some elegant proof to this (and I would love it if there were), but I wouldn't hold my breath. Thing is, your procedure is deeply rooted in base ten. And there is no simple way to interleave base ten dependent stuff with base independent stuff like primeness. That being said, it's an interesting question. – Arthur Dec 11 '17 at 12:04
• $131$ is the smallest number giving $4$ primes , $2111$ the smallest number giving $5$ primes. – Peter Dec 11 '17 at 12:10
• $\color\red {12\ 815\ 137}$ gives $6$ primes. – Peter Dec 11 '17 at 12:18
• According to my calculation, $7$ (or more) primes don't appear upto $3\cdot 10^8$ – Peter Dec 11 '17 at 12:57
• According to my furhter calculation , $7$ or more primes do not occur upto $4.6\cdot 10^9$. – Peter Dec 11 '17 at 21:03

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>
?

• I've recently found it especially helpful to always state the programming language used in a piece of presented code. This can save others the trouble of guessing (looks like GP to me, but not everyone is as familiar). Cheers! – Matthew Conroy Dec 12 '17 at 3:58
• @Peter - FYI, my own Sage program produces this same list. Also, starting with the prime $5064291151$ (which generates a chain of $6$ primes), I tested the next $1.26\,10^9$ primes without finding any that generate a chain of $7$ primes. In this range of primes, $33861214627$ is the largest that produces a chain of length $6$. (I started at $5064291151$ because I thought someone posted that they'd tested up to that number and had found no chains of length $7$. Now I can't find that posting, though.) – r.e.s. Dec 13 '17 at 2:23
• Okay ... I've now checked all primes up to $36043180087\ \ (\approx 3.6\, 10^{10})$, with the result that none of them produce a chain of length greater than $6$. – r.e.s. Dec 14 '17 at 0:17
• Surprise! The $12$-digit prime $103723971119$ produces a chain of length $7$ and is the least prime that produces a chain longer than $6$. (Among the primes less than this, there are $67$ that produce chains of length $6$.) – r.e.s. Dec 15 '17 at 14:28
• It has $102$ digits. – r.e.s. Dec 15 '17 at 14:57