All the terms of an
arithmetic progression having the first term as 2 with common difference 4 and the last term as 2010, are written successively without commas or spaces, resulting in the following pattern:
2610141822263034384246.........20062010
Determine the sum of all the digits in the above pattern.
We're just summing the digits in the given arithmetic progression. It helps to take a look at the first few, listed in columns by decade:
02 10 22 30 . 82 90
06 14 26 34 . 86 94
18 38 . 98
The units digit repeats in a cycle of 5: 2,6,0,4,8, with a sod for this cycle totalling 20. The entire series contains (2010  2) / 4 + 1 numbers. That's 503, or 100 cycles of 5 plus three more. So the sod of all the units digits is 20*100 + 8, as 8 is the sod of the first three digits in the 5cycle.
Therefore the units digits account for a sod component of 2008.
In the tens position, within each 100/4 = 25 numbers of the sequence, there are two of each even digit and three of each odd. One set of the odd digits adds to 25 and one set of the even digits sums to 20, so each 25 numbers contribute 3*25 + 2*20 = 115 via the tens position. In the first 500 numbers of the sequence this accounts for 20*115 = 2300 and the remaining three contribute only 1, as the first two tens positions are zero and the last a one.
So, in total, the tens positions contribute 2301 to the overall sod.
There are 25 numbers within each occurrence of a given hundreds digit, so there are 20 full groupings of that type, meaning that each hundreds digit is gone through twice, with 25 occurrences each time. In the final three, they're all zero and so don't matter.
So the hundreds positions contribute 2*25*45 = 2250 to the sod.
In the thousands position, 250 are zero, 250 are 1 and three are 2.
So the thousands positions add up to 250 + 3*2 = 256.
The overall sod is thus 2008+2301+2250+256=6815.
Or, much faster:
FOR n = 2 TO 2010 STEP 4
s$ = LTRIM$(STR$(n))
FOR i = 1 TO LEN(s$)
sod = sod + VAL(MID$(s$, i, 1))
NEXT
NEXT
PRINT sod
6815

Posted by Charlie
on 20100325 11:45:29 