A225580 The sum of all substrings of n (including n).
1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 66, 68, 70, 72, 74, 76, 78, 80
Offset: 1
Examples
For n=1980, a(n) = 1 + 9 + 8 + 0 + 19 + 98 + 80 + 198 + 980 + 1980 = 3373. Note that A071980(1980) = 3258, because it does not include 9, 8, 98 in the sum.
Links
- Christian N. K. Anderson, Table of n, a(n) for n = 1..10000
- Christian N. K. Anderson, Ulam spiral of all values of a(n)<10000, color-coded by the number of times they occur.
Programs
-
Maple
f:= proc(n) local i,d,L; L:= convert(n,base,10); d:= nops(L); add(L[i]*(d-i+1)*(10^i - 1)/9, i=1..d); end proc: map(f, [$1..100]); # Robert Israel, May 15 2025
-
Mathematica
Table[s = IntegerDigits[n]; Total[Flatten[Table[FromDigits /@ Partition[s, i, 1], {i, Length[s]}]]], {n, 100}] (* T. D. Noe, May 13 2013 *)
-
Python
def a(n): s = str(n) return sum(int(s[i:j]) for j in range(1, len(s)+1) for i in range(j)) # David Radcliffe, May 15 2025
-
R
sapply(1:100,function(n) {tot=0; s=as.character(n); len=nchar(s); for(i in 1:len) for(j in i:len) tot=tot+as.numeric(substr(s,i,j)); tot})
Formula
a(n) = 11*a(floor(n/10)) - 10*a(floor(n/100)) + (n mod 10) * A055642(n). - David Radcliffe, May 15 2025
Extensions
Example corrected by Zak Seidov, May 16 2013
Comments