View Single Post
Old 2006-09-20, 12:34   #2
AntonVrba
 
AntonVrba's Avatar
 
Jun 2005

6216 Posts
Default

For the Mathematica users
Code:
CumSumDigits[n_, b_] := Module[
    {ss, p, d0, d1, m} ,
    ss = p = d0 = 0 ;
    m = n ;
While[m > 0, {
If[(d1 = Mod[m, b]) != 0, {
   ss += d1( b^p(b - 1) p + b^p (d1 - 1) + 2(d0 + 1))/2,
   d0 += b^p d1}],
p += 1,
m = IntegerPart[m/b],
}] ;
Return [ss ] ;
    ]
and can be checked by evaluating
Code:
CumSumDigits[(10^123 - 1)/9, 10] - CumSumDigits[(10^123 - 1)/9 - 1, 10]
AntonVrba is offline   Reply With Quote