All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars
 perplexus dot info

 Summing Ones (Posted on 2013-02-27)
Find the sum
1+11+111+.......+111..111(n digits)

 No Solution Yet Submitted by Danish Ahmed Khan No Rating

Comments: ( Back to comment list | You must be logged in to post comments.)
 solution | Comment 2 of 4 |

10   T=1:Tot=T:Proto=123456790//999999999
20   for N=2 to 45
30     T=T*10+1:Tot=Tot+T
35     Approx=int(10^N*Proto)
40      print N,Tot,Approx-Tot
41     Prev=Approx-Tot
50   next

shows sums for n=2 through 45 together with the difference between this and an approximation based on a previous run of a simpler version of the program:

2       12      0
3       123     0
4       1234    0
5       12345   0
6       123456          0
7       1234567         0
8       12345678        1
9       123456789       1
10      1234567900      1
11      12345679011     1
12      123456790122    1
13      1234567901233   1
14      12345679012344          1
15      123456790123455         1
16      1234567901234566        1
17      12345679012345677       2
18      123456790123456788      2
19      1234567901234567899     2
20      12345679012345679010    2
21      123456790123456790121   2
22      1234567901234567901232          2
23      12345679012345679012343         2
24      123456790123456790123454        2
25      1234567901234567901234565       2
26      12345679012345679012345676      3
27      123456790123456790123456787     3
28      1234567901234567901234567898    3
29      12345679012345679012345679009   3
30      123456790123456790123456790120          3
31      1234567901234567901234567901231         3
32      12345679012345679012345679012342        3
33      123456790123456790123456790123453       3
34      1234567901234567901234567901234564      3
35      12345679012345679012345679012345675     4
36      123456790123456790123456790123456786    4
37      1234567901234567901234567901234567897   4
38      12345679012345679012345679012345679008          4
39      123456790123456790123456790123456790119         4
40      1234567901234567901234567901234567901230        4
41      12345679012345679012345679012345679012341       4
42      123456790123456790123456790123456790123452      4
43      1234567901234567901234567901234567901234563     4
44      12345679012345679012345679012345679012345674    5
45      123456790123456790123456790123456790123456785   5

The discrepancy increases by 1 every ninth value of n. This is shown farther down the list by:

10   T=1:Tot=T:Proto=123456790//999999999
20   for N=2 to 200
30     T=T*10+1:Tot=Tot+T
35     Approx=int(10^N*Proto)
40     if Approx-Tot<>Prev then print N;Approx-Tot
41     Prev=Approx-Tot
50   next

8  1
17  2
26  3
35  4
44  5
53  6
62  7
71  8
80  9
89  10
98  11
107  12
116  13
125  14
134  15
143  16
152  17
161  18
170  19
179  20
188  21
197  22

The reduced value of proto is actually 10/81.

The initial approximation is [10^n * 10/81] where the square brackets indicate the floor function. But to take into consideration the growing discrepancy from the approximation, we need to subtract [(n+1)/9].

Putting the two together and simplifying we get:

[10^(n+1) / 81] - [(n+1)/9]

As verification, this:

10   T=1:Tot=T:Proto=123456790//999999999
20   for N=2 to 2000
30     T=T*10+1:Tot=Tot+T
35     Approx=int(10^(N+1)//81)-int((n+1)//9)
40     if Approx-Tot<>Prev then print N;Approx-Tot
41     Prev=Approx-Tot
50   next

produces no output, as Prev starts out and stays zero.

 Posted by Charlie on 2013-02-27 13:23:06

 Search: Search body:
Forums (0)