> 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/i/increasing_gaps_between_consecutive_niven_numbers.md).

# Increasing gaps between consecutive Niven numbers

```ruby
var threshold = 10_000_000

say "Gap    Index of gap  Starting Niven"
for (var (n=1, index=0, gap=0, prev=1); index <= threshold; ++n) {
    n.is_div(n.digits_sum) || next
    if ((var diff = (n - prev)) > gap) {
        gap = diff
        printf("%3d %15s %15s\n", gap, index, prev)
    }
    prev = n
    ++index
}
```

#### Output:

```
Gap    Index of gap  Starting Niven
  1               1               1
  2              10              10
  6              11              12
  7              26              63
  8              28              72
 10              32              90
 12              83             288
 14             102             378
 18             143             558
 23             561            2889
 32             716            3784
 36            1118            6480
 44            2948           19872
 45            4194           28971
 54            5439           38772
 60           33494          297864
 66           51544          478764
 72           61588          589860
 88           94748          989867
 90          265336         2879865
 99          800054         9898956
108         3750017        49989744
126         6292149        88996914
```


---

# 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/i/increasing_gaps_between_consecutive_niven_numbers.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.
