# Primality by trial division

```ruby
func is_prime(a) {
  given (a) {
    when (2)                   { true  }
    case (a <= 1 || a.is_even) { false }
    default                    { 3 .. a.isqrt -> any { .divides(a) } -> not }
  }
}
```

Alternative version, excluding multiples of 2 and 3:

```ruby
func is_prime(n) {
    return (n >= 2) if (n < 4)
    return false if (n%%2 || n%%3)
    for k in (5 .. n.isqrt -> by(6)) {
        return false if (n%%k || n%%(k+2))
    }
    return true
}
```


---

# 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/p/primality_by_trial_division.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.
