cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A039997 Number of distinct primes which occur as substrings of the digits of n.

This page as a plain text file.
%I A039997 #24 Aug 09 2022 17:13:15
%S A039997 0,1,1,0,1,0,1,0,0,0,1,1,2,0,1,0,2,0,1,1,1,1,3,1,2,1,2,1,2,1,2,2,1,1,
%T A039997 2,1,3,1,1,0,1,1,2,0,1,0,2,0,0,1,1,2,3,1,1,1,2,1,2,0,1,1,1,0,1,0,2,0,
%U A039997 0,1,2,2,3,1,2,1,1,1,2,0,0,1,2,0,1,0,1,0,1,0,0,1,1,0,1,0,2,0,0,0,1,1,2,0,1
%N A039997 Number of distinct primes which occur as substrings of the digits of n.
%H A039997 Reinhard Zumkeller, <a href="/A039997/b039997.txt">Table of n, a(n) for n = 1..10000</a>
%F A039997 a(A062115(n)) = 0; a(A093301(n)) = n and a(m) <> n for m < A093301(n). - _Reinhard Zumkeller_, Jul 16 2007
%F A039997 a(A163753(n)) > 0; a(A205667(n)) = 1. [_Reinhard Zumkeller_, Jan 31 2012]
%e A039997 a(22) = 1 because 22 has two substrings which are prime but they are identical. a(103) = 2, since the primes 3 and 103 occur as substrings.
%p A039997 a:= n-> (s-> nops(select(t -> t[1]<>"0" and isprime(parse(t)),
%p A039997         {seq(seq(s[i..j], i=1..j), j=1..length(s))})))(""||n):
%p A039997 seq(a(n), n=1..100);  # _Alois P. Heinz_, Aug 09 2022
%t A039997 a[n_] := Block[{s = IntegerDigits[n], c = 0, d = {}}, l = Length[s]; t = Flatten[ Table[ Take[s, {i, j}], {i, 1, l}, {j, i, l}], 1]; k = l(l + 1)/2; While[k > 0, If[ t[[k]][[1]] != 0, d = Append[d, FromDigits[ t[[k]] ]]]; k-- ]; Count[ PrimeQ[ Union[d]], True]]; Table[ a[n], {n, 1, 105}]
%o A039997 (Haskell)
%o A039997 import Data.List (isInfixOf)
%o A039997 a039997 n = length [p | p <- takeWhile (<= n) a000040_list,
%o A039997                         show p `isInfixOf` show n]
%o A039997 a039997_list = map a039997 [1..]
%o A039997 -- _Reinhard Zumkeller_, Jan 31 2012
%o A039997 (PARI) dp(n)=if(n<12,return(if(isprime(n),[n],[])));my(v=vecsort(select(isprime, eval(Vec(Str(n)))),,8),t);while(n>9,if(gcd(n%10,10)>1,n\=10;next);t=10; while((t*=10)<n*10, if(isprime(n%t),v=concat(v,n%t)));v=vecsort(v,,8);n\=10);v
%o A039997 a(n)=#dp(n) \\ _Charles R Greathouse IV_, Jul 10 2012
%o A039997 (Python)
%o A039997 from sympy import isprime
%o A039997 def a(n):
%o A039997     s = str(n)
%o A039997     ss = (int(s[i:j]) for i in range(len(s)) for j in range(i+1, len(s)+1))
%o A039997     return len(set(k for k in ss if isprime(k)))
%o A039997 print([a(n) for n in range(1, 106)]) # _Michael S. Branicky_, Aug 07 2022
%Y A039997 Different from A039995 after the 100th term. Cf. A035232.
%K A039997 nonn,base
%O A039997 1,13
%A A039997 _David W. Wilson_
%E A039997 Edited by _Robert G. Wilson v_, Feb 24 2003