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

# Primes which contain only one odd digit

```ruby
func primes_with_one_odd_digit(upto, base = 10) {

    upto = prev_prime(upto+1)

    var list = []
    var digits = @(^base)

    var even_digits = digits.grep { .is_even }
    var odd_digits  = digits.grep { .is_odd && .is_coprime(base) }

    list << digits.grep { .is_odd && .is_prime && !.is_coprime(base) }...

    for k in (0 .. upto.ilog(base)) {
        even_digits.variations_with_repetition(k, {|*a|
            next if (a.last == 0)
            var v = a.digits2num(base)
            odd_digits.each {|d|
                var n = (v*base + d)
                list << n if (n.is_prime && (n <= upto))
            }
        })
    }

    list.sort
}

with (1e3) {|n|
    var list = primes_with_one_odd_digit(n)
    say "There are #{list.len} primes under #{n.commify} which contain only one odd digit:"
    list.each_slice(9, {|*a| say a.map { '%3s' % _ }.join(' ') })
}

say ''

for k in (1..8) {
    var count = primes_with_one_odd_digit(10**k).len
    say "There are #{'%6s' % count.commify} such primes <= 10^#{k}"
}
```

#### Output:

```
There are 45 primes under 1,000 which contain only one odd digit:
  3   5   7  23  29  41  43  47  61
 67  83  89 223 227 229 241 263 269
281 283 401 409 421 443 449 461 463
467 487 601 607 641 643 647 661 683
809 821 823 827 829 863 881 883 887

There are      3 such primes <= 10^1
There are     12 such primes <= 10^2
There are     45 such primes <= 10^3
There are    171 such primes <= 10^4
There are    619 such primes <= 10^5
There are  2,560 such primes <= 10^6
There are 10,774 such primes <= 10^7
There are 46,708 such primes <= 10^8
```


---

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