login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A035232 Number of substrings of n which are primes (counted with multiplicity). 62

%I #16 Nov 15 2022 11:42:29

%S 0,1,1,0,1,0,1,0,0,0,1,1,2,0,1,0,2,0,1,1,1,2,3,1,2,1,2,1,2,1,2,2,2,1,

%T 2,1,3,1,1,0,1,1,2,0,1,0,2,0,0,1,1,2,3,1,2,1,2,1,2,0,1,1,1,0,1,0,2,0,

%U 0,1,2,2,3,1,2,1,2,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 Number of substrings of n which are primes (counted with multiplicity).

%C No leading 0's allowed in substrings.

%H Michael S. Branicky, <a href="/A035232/b035232.txt">Table of n, a(n) for n = 1..10000</a>

%F Trivial upper bound: a(n) <= binomial(floor(log(n)/log(10)+2), 2) ~ k*log^2 n with k = 0.09430584850580... = 1/log(10)^2/2. - _Charles R Greathouse IV_, Nov 15 2022

%e The primes occurring as substrings of 37 are 3, 7, 37, so a(37) = 3.

%e a(22) = 2, since the prime 2 occurs twice as a substring.

%p a:= n-> (s-> nops(select(t -> t[1]<>"0" and isprime(parse(t)),

%p [seq(seq(s[i..j], i=1..j), j=1..length(s))])))(""||n):

%p seq(a(n), n=1..100); # _Alois P. Heinz_, Aug 07 2022

%t 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[d], True]]; Table[ a[n], {n, 1, 105}]

%o (Python)

%o from sympy import isprime

%o def a(n):

%o s = str(n)

%o ss = (s[i:j] for i in range(len(s)) for j in range(i+1, len(s)+1))

%o return sum(1 for w in ss if w[0] != "0" and isprime(int(w)))

%o print([a(n) for n in range(1, 106)]) # _Michael S. Branicky_, Aug 07 2022

%Y Cf. A039997, A039995.

%K base,easy,nonn

%O 1,13

%A _Erich Friedman_

%E Edited by _Robert G. Wilson v_, Feb 24 2003

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified July 23 06:04 EDT 2024. Contains 374544 sequences. (Running on oeis4.)