Let P(n) be the product of non-zero digits of the number n.Find the value of P(1)+P(2)+P(3).......P(2012)
The sum of the first 9 digits is 45 and this would be the sum for P(1) to P(9).
For 2-digit numbers, 10 through 99, the 45 is multiplied by the 9th triangular number, i.e. that same 45, but also add in another 45 for the 2-digit numbers with zero in the units position, so the 2-digit numbers account for 45*45+45=2070.
Similarly, 3-digit numbers account for 45*(45+45*45+45)+45 = 95220 as all the 1-digit and 2-digit numbers are repeated with 100, 200, ... added and those with two trailing zeros account for the additional 45.
The 1 thousands will result in 45*(45+2070+95220) plus 1 more for 1000 itself, making 97336.
Then 2000 through 2009 account for 2+2*45 = 92.
Finally 2010, 2011 and 2012 account for 2+2+4 = 8.
45
2070
95220
97336
92
8
-------
194771
computer method:
list
10 for N=1 to 2012
20 D=cutspc(str(N))
30 P=1
40 for I=1 to len(D)
50 if mid(D,I,1)>"0" then P=P*val(mid(D,I,1))
60 next
70 Tot=Tot+P
80 next
90 print Tot
OK
run
194771
OK
|
Posted by Charlie
on 2012-12-05 17:33:44 |