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

# Integer roots

```ruby
func root(a, b) {
    b < 2 && return(b)
    var (a1, c) = (a-1, 1)
    var f = {|x| (a1*x + b//(x**a1)) // a }
    var d = f(c)
    var e = f(d)
    while (c !~ [d, e]) {
        (c, d, e) = (d, e, f(e))
    }
    [d, e].min
}
 
say "First 2,001 digits of the square root of two:"
say root(2, 2 * 100**2000)
```

#### Output:

```
First 2,001 digits of the square root of two:
14142135623730950488016887242096980[...]32952546758516447107578486024636008
```
