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