Determine a general formula (in terms of n) for the sum of the first n positive integers that are not divisible by 5.
I see that the below "solution" misinterprets what is asked. It has the sum of the first n positive integers minus the multiples of 5:
n*(n+1)/2 - [n/5]*([n/5] + 1)*5/2
where [ ] represents the floor function.
To test it:
DEFDBL A-Z
CLS
FOR n = 1 TO 45
PRINT n, n * (n + 1) / 2 - INT(n / 5) * (INT(n / 5) + 1) * 5 / 2
NEXT
n sum
1 1
2 3
3 6
4 10
5 10
6 16
7 23
8 31
9 40
10 40
11 51
12 63
13 76
14 90
15 90
16 106
17 123
18 141
19 160
20 160
21 181
22 203
23 226
24 250
25 250
26 276
27 303
28 331
29 360
30 360
31 391
32 423
33 456
34 490
35 490
36 526
37 563
38 601
39 640
40 640
41 681
42 723
43 766
44 810
45 810
Edited on March 18, 2014, 3:19 pm
|
Posted by Charlie
on 2014-03-18 15:10:39 |