> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/s/sum_multiples_of_3_and_5.md).

# Sum multiples of 3 and 5

```ruby
func sumMul(n, f) {
    var m = int((n - 1) / f)
    f * m * (m + 1) / 2
}

func sum35(n) {
    sumMul(n, 3) + sumMul(n, 5) - sumMul(n, 15)
}

for i in (1..20) {
    printf("%2s:%22s %s\n", i, 10**i, sum35(10**i))
}
```

#### Output:

```
 1:                    10 23
 2:                   100 2318
 3:                  1000 233168
 4:                 10000 23331668
 5:                100000 2333316668
 6:               1000000 233333166668
 7:              10000000 23333331666668
 8:             100000000 2333333316666668
 9:            1000000000 233333333166666668
10:           10000000000 23333333331666666668
11:          100000000000 2333333333316666666668
12:         1000000000000 233333333333166666666668
13:        10000000000000 23333333333331666666666668
14:       100000000000000 2333333333333316666666666668
15:      1000000000000000 233333333333333166666666666668
16:     10000000000000000 23333333333333331666666666666668
17:    100000000000000000 2333333333333333316666666666666668
18:   1000000000000000000 233333333333333333166666666666666668
19:  10000000000000000000 23333333333333333331666666666666666668
20: 100000000000000000000 2333333333333333333316666666666666666668
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/s/sum_multiples_of_3_and_5.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
