login
Total number of primes that are both left-truncatable and right-truncatable in base n.
2

%I #27 Feb 16 2025 08:33:57

%S 0,2,3,5,9,7,22,8,15,6,35,11,37,17,22,12,69,12,68,18,44,13,145,16,47,

%T 20,77,13,291,15,89,27,74,20,241,18,106,25,134,15,450,23,144,33,131,

%U 24,491,27,235,29,187,23,575,30,218,31,183,25,1377,26,247,37,231

%N Total number of primes that are both left-truncatable and right-truncatable in base n.

%H Chris Caldwell, <a href="https://primes.utm.edu/glossary/page.php?sort=RightTruncatablePrime">right-truncatable prime</a>, The Prime Glossary.

%H Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/TruncatablePrime.html">Truncatable Prime</a>

%e For n = 2, there are no both-truncatable primes, therefore a(2) = 0.

%e For n = 3, there are 2 both-truncatable primes: 2, 23.

%e For n = 4, there are 3 both-truncatable primes: 2, 3, 11.

%e For n = 5, there are 5 both-truncatable primes: 2, 3, 13, 17, 67.

%e For n = 6, there are 9 both-truncatable primes: 2, 3, 5, 17, 23, 83, 191, 479, 839.

%o (PARI)

%o digitsToNum(d, base) = sum(k=1, #d, base^(k-1) * d[k]);

%o isLeftTruncatable(d, base) = my(ok=1); for(k=1, #d, if(!isprime(digitsToNum(d[1..k], base)), ok=0; break)); ok;

%o generateFromPrefix(p, base) = my(seq = [p]); for(n=1, base-1, my(t=concat(n, p)); if(isprime(digitsToNum(t, base)), seq=concat(seq, select(v -> isLeftTruncatable(v, base), generateFromPrefix(t, base))))); seq;

%o bothTruncatablePrimesInBase(base) = my(t=[]); my(P=primes(primepi(base-1))); for(k=1, #P, t=concat(t, generateFromPrefix([P[k]], base))); vector(#t, k, digitsToNum(t[k], base));

%o a(n) = #(bothTruncatablePrimesInBase(n));

%Y Cf. A020994, A076623, A076586, A323137, A323396.

%K nonn,base,changed

%O 2,2

%A _Daniel Suteu_, Jan 13 2019