# last non-zero digit sum

$\sum_{n=p}^{n=q} F(n)$

where F(n) is last non-zero digit of n and $1 \leq p \leq q \leq 2^{31}$

For example,

F(1050) = 5

F(1008) = 8

F(2000) = 2

Can anyone help me how to get the result using number tricks?

The last non-zero digit follow this pattern :

$\underbrace{123456789}_{u_1}$

$\underbrace{u_1 1 u_1 2 u_1 3 u_1 4 u_1 5 u_1 6 u_1 7 u_1 8 u_1 9 u_1}_{u_2}$

$\underbrace{u_2 1 u_2 2 u_2 3 u_2 4 u_2 5 u_2 6 u_2 7 u_2 8 u_2 9 u_1}_{u_3}$

So you just have to calculate the sum for $u_1$, $u_2$, $u_3$ , $\cdots$ and find where your sum begin and end. Then you can be smart, and calculate the number of each $u_n$ you'll need

For exemple, between 3456 and 11578, I have the sequence

$67896u_17u_18u_19u_1 5 u_2 6 u_2 7 u_2 8 u_2 9 u_2 4 u_3 5 u_3 6u_3 7u_3 8u_39u_31$ (we're at 10000)

$u_31 u_22u_23u_2 4u_2 5 u_1 1 u_1 2 u_13 u_1 4 u_1 5 u_1 6 u_1 7 12345678$

So, I need:

• "6789" to get to the next 10,
• "6789" + 4*$u_1$ to get to the next 100,
• "56789" + 5*$u_2$ to get to the next 1000,
• "45678911" + 8*$u_3$ to get to 11000 etc.

So by the same reasonning, if I want the sequence between 684551 and 767894, I'll will need :

• "23456789" to get to 684560 (the numbers after the 1)
• "6789" +4$u_1$ to get to 684600 (the numbers after the 5)
• "6789" +4$u_2$ to get to 685000 (the numbers after the 5)
• "56789" +5$u_3$ to get to 690000 (the numbers after the 4)
• "9" +1$u_4$ to get to 700000 (the numbers after the 8)
• "7" (we're at 700000)
• "123456" + 6$u_4$ to get to 760000
• "1234567" + 7$u_3$ to get to 767000
• "12345678" + 8$u_2$ to get to 767800
• "123456789" + 9 $u_1$ to get to 767890
• "1234" to get to 767894
• what is the pattern for u4, u5,...? – Shadekur Rahman Jan 1 '16 at 16:23
• @ShadekurRahman : $u_{n+1} = u_n1u_n2u_n3u_n4u_n5u_n6u_n7u_n8u_n9u_n$ – Tryss Jan 1 '16 at 18:43