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

# Prime numbers which contain 123

```ruby
func numbers_with_subdigits(upto, base = 10, s = 123.digits(base)) {
    Enumerator({|callback|
        for k in (0 .. base**(upto.len(base) - s.len)) {

            var d = k.digits(base)

            for i in (0 .. d.len) {
                var n = d.clone.insert(i, s...).digits2num(base)
                callback(n) if (n <= upto)
            }

            var z = d.clone.insert(d.len, s...)
            loop {
                var n = z.insert(d.len, 0).digits2num(base)
                (n <= upto) ? callback(n) : break
            }
        }
    })
}

say "Decimal primes under 100,000 which contain '123':"
numbers_with_subdigits(1e5).grep { .is_prime }.sort.each_slice(10, {|*a|
    say a.map { '%6s' % _ }.join(' ')
})

say ''

for n in (4..8) {
    var count = numbers_with_subdigits(10**n).grep { .is_prime }.len
    say "Found #{'%6s' % count.commify} such primes < 10^#{n}"
}
```

## Output:

```
Decimal primes under 100,000 which contain '123':
  1123   1231   1237   8123  11239  12301  12323  12329  12343  12347
 12373  12377  12379  12391  17123  20123  22123  28123  29123  31123
 31231  31237  34123  37123  40123  41231  41233  44123  47123  49123
 50123  51239  56123  59123  61231  64123  65123  70123  71233  71237
 76123  81233  81239  89123  91237  98123

Found      4 such primes < 10^4
Found     46 such primes < 10^5
Found    451 such primes < 10^6
Found  4,412 such primes < 10^7
Found 43,548 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/prime_numbers_which_contain_123.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.
