A365276 Sum of all prime substrings of n in base 10, including n itself and duplicate or overlapping substrings but not substrings with a leading 0.
0, 0, 2, 3, 0, 5, 0, 7, 0, 0, 0, 11, 2, 16, 0, 5, 0, 24, 0, 19, 2, 2, 4, 28, 2, 7, 2, 9, 2, 31, 3, 34, 5, 6, 3, 8, 3, 47, 3, 3, 0, 41, 2, 46, 0, 5, 0, 54, 0, 0, 5, 5, 7, 61, 5, 10, 5, 12, 5, 64, 0, 61, 2, 3, 0, 5, 0, 74, 0, 0, 7, 78, 9, 83, 7, 12, 7, 14, 7, 86, 0
Offset: 0
Examples
a(25) = 2 + 5 = 7. a(37) = 3 + 7 + 37 = 47. a(3002) = 3 + 2 = 5. a(1235) = 2 + 3 + 5 + 23 = 33. Example including duplicate and overlapping prime substrings: a(227111) = 2 + 2 + 7 + 11 + 11 + 71 + 227 + 271 + 2711 + 227111 = 230424. Note that in the above example, the substring 2 is incorporated into the sum twice because it appears twice in n. The same is true of the substring 11, whose two appearances overlap each other in the final three digits of n. Example wherein substrings with a leading 0 are to be ignored: a(1002) = 2 because the substrings 002 and 02 are to be ignored due to the presence of a leading 0.
Programs
-
PARI
a(n)={my(v=digits(n)); sum(j=1, #v, sum(i=1, j, if(v[i], my(t=fromdigits(v[i..j])); t*isprime(t))))} \\ Andrew Howroyd, Aug 30 2023
-
Python
from sympy import isprime def a(n): s = str(n) ss = (s[i:j] for i in range(len(s)) for j in range(i+1, len(s)+1)) return sum(p for w in ss if w[0]!="0" and isprime(p:=int(w))) print([a(n) for n in range(81)]) # Michael S. Branicky, Aug 30 2023
Extensions
More terms from Andrew Howroyd, Aug 30 2023