# Wolstenholme numbers

```ruby
say "Wolstenholme numbers:"

for n in (1..20) {
    say ("#{'%5s'%n}: ", sum(1..n, {|k| 1/k**2 }).nu)
}

for n in (500, 1000, 2500, 5000, 10000) {
    var w = Str(sum(1..n, {|k| 1/k**2 }).nu)
    say ("#{'%5s'%n}: ", w.first(20), '...', w.last(20), " (#{w.len} digits)")
}

say "\nPrime Wolstenholme numbers:"

Enumerator({|callback|
    var w = 0
    for k in (1..Inf) {
        w += 1/k**2
        if (w.nu.is_prime) {
            callback([k, w.nu])
        }
    }
}).first(15).each_2d {|n,p|
    var w = Str(p)
    if (w.len > 50) {
        w = join('', w.first(20), '...', w.last(20), " (#{w.len} digits)")
    }
    say ("#{'%5s'%n}: ", w)
}
```

#### Output:

```
Wolstenholme numbers:
    1: 1
    2: 5
    3: 49
    4: 205
    5: 5269
    6: 5369
    7: 266681
    8: 1077749
    9: 9778141
   10: 1968329
   11: 239437889
   12: 240505109
   13: 40799043101
   14: 40931552621
   15: 205234915681
   16: 822968714749
   17: 238357395880861
   18: 238820721143261
   19: 86364397717734821
   20: 17299975731542641
  500: 40989667509417020364...48084984597965892703 (434 digits)
 1000: 83545938483149689478...99094240207812766449 (866 digits)
 2500: 64537911900230612090...12785535902976933153 (2164 digits)
 5000: 34472086597488537716...22525144829082590451 (4340 digits)
10000: 54714423173933343999...49175649667700005717 (8693 digits)

Prime Wolstenholme numbers:
    2: 5
    7: 266681
   13: 40799043101
   19: 86364397717734821
  121: 36190908596780862323...79995976006474252029 (104 digits)
  188: 33427988094524601237...48446489305085140033 (156 digits)
  252: 22812704758392002353...84405125167217413149 (218 digits)
  368: 28347687473208792918...45794572911130248059 (318 digits)
  605: 78440559440644426017...30422337523878698419 (520 digits)
  745: 22706893975121925531...02173859396183964989 (649 digits)
 1085: 27310394808585898968...86311385662644388271 (935 digits)
 1127: 13001072736642048751...08635832246554146071 (984 digits)
 1406: 15086863305391456002...05367804007944918693 (1202 digits)
 1743: 23541935187269979100...02324742766220468879 (1518 digits)
 1774: 40306783143871607599...58901192511859288941 (1539 digits)
```


---

# Agent Instructions: 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:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/w/wolstenholme_numbers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
