%I #24 Oct 26 2019 18:00:37
%S 2,23,31,101,103,307,701,1009,9001,10007,70001,100003,300007,700001,
%T 1000003,3000017,7000003,30000001,100000007,700000001,1000000007,
%U 7000000001,10000000019,90000000019,90000000023,300000000077
%N a(1) = 2; a(n+1) = smallest prime > a(n) with leading digit equal to final digit of a(n).
%C From _R. J. Mathar_, Feb 15 2012: (Start)
%C Starting with other primes we find:
%C 3, 31, 101, 103, 307, 701, 1009, 9001, 10007,.. or
%C 5, 53, 307, 701, 1009, 9001, 10007, 70001, 10000.... or
%C 7, 71, 101, 103, 307, 701, 1009, 9001, 10007, 70001 .. or
%C 11, 13, 31, 101, 103, 307, 701, 1009, 9001,.. or
%C 13, 31, 101, 103, 307, 701, 1009, 9001,.. or
%C 17, 71, 101, 103, 307, 701, 1009, 9001, 10007,.. or
%C 19, 97, 701, 1009, 9001, 10007, 70001, 100003,.. (End)
%H <a href="/index/Fi#final">Index entries for sequences related to final digits of numbers</a>
%F a(n) = A054262(n-1), n>2. - _R. J. Mathar_, Jan 30 2009
%e a(5) = 103, hence a(6) = 307.
%p A061448 := proc(n)
%p option remember;
%p local a,sdig,adgs,ad ;
%p if n = 1 then
%p 2;
%p else
%p sdig := procname(n-1) mod 10 ;
%p a := nextprime(procname(n-1)) ;
%p while true do
%p adgs := convert(a,base,10) ;
%p ad := op(-1,adgs) ;
%p if op(-1,adgs) = sdig then
%p if isprime(a) then
%p return a;
%p end if;
%p elif ad > sdig then
%p a := sdig*10^nops(adgs) ;
%p elif ad < sdig then
%p a := sdig*10^(nops(adgs)-1) ;
%p end if;
%p a := nextprime(a) ;
%p end do:
%p end if;
%p end proc: # _R. J. Mathar_, Feb 15 2013
%t a[1]=2; a[n_] := (v=IntegerDigits[a[n-1]]; v1=If[v[[ -1]]>v[[1]], v[[ -1]]*10^(Length[v]-1), If[v[[ -1]]<v[[1]]||Length[v]==1, v[[ -1]]*10^Length[v], a[n-1]]]; For[m=v1+1, !PrimeQ[m], m++ ]; m); Table[a[n], {n, 35}] (* _Farideh Firoozbakht_, Aug 30 2003 *)
%K nonn,base
%O 1,1
%A _Amarnath Murthy_, May 03 2001
%E More terms from Larry Reeves (larryr(AT)acm.org), May 17 2001
%E Terms from a(18) added by _Patrick De Geest_, Jun 04 2001