Showing posts with label embedded. Show all posts
Showing posts with label embedded. Show all posts

Monday, 19 October 2026

Embedded Primes Versus Prime Partitions

I noticed that the number associated with my diurnal age today (28323), while not prime, has digits that are all prime with the exception of 8 and it also has two other primes contained within it (283 and 23). I asked Gemini the following question:

28323 is a composite number with the property that it is a concatenation of prime numbers in various ways e.g. 283 || 23 and 2 || 83 || 23 where I’ve used the symbol || for concatenation. Write a program in SageMath that will identify all composite numbers in a given range that are concatenations of prime numbers in two or more different ways. The output should be a list of comma-separated numbers. The default range can be from 4 to 40000 and the upper and lower limits of the range should be easily adjustable. There should also be a switch so that the program can search for prime numbers with the same property, although the default should be set to composite. The number of suitable concatenations should be adjustable as well, although 2 is to be the default. Can a count of the suitable numbers be included in the output, underneath the list of numbers.

The program as requested is quite flexible. Below are the opening lines of code:

# --- Adjustable Parameters ---

LOWER_LIMIT = 4

UPPER_LIMIT = 40000

SEARCH_PRIMES = True  # False = search for composite numbers (default), True = search for primes

MIN_WAYS = 11         # Minimum number of valid prime concatenations required

# -----------------------------

Using these settings and thus searching for all primes in the range from 4 to 40000 that can be concatenated in at least 11 different ways, I found only a single number: 37337 (permalink). However, OEIS A179919 that lists primes with eleven embedded primes listed 111317 as the first number. Clearly I was confused and I sought clarification from Gemini. Here is its explanation:

The discrepancy comes down to two fundamentally different mathematical definitions: full-string prime partitions (concatenations) versus distinct proper prime substrings (embedded primes).

Your SageMath program counts the number of ways an entire number can be sliced into a complete concatenation of prime pieces from left to right, whereas OEIS A179919 counts how many distinct prime numbers appear anywhere inside the number as contiguous substrings (excluding the prime itself).

1. What Your Program Counts: Prime Concatenations (37337)

Your program requires every single digit of the number to be used in each partition. A 5-digit number has 2^{5-1} - 1 = 15 possible ways to be sliced into two or more contiguous pieces.

For the prime number 37337, 11 of those 15 full-string partitions consist entirely of prime numbers:

  1. 3 || 7 || 3 || 3 || 7

  2. 3 || 7 || 3 || 37

  3. 3 || 7 || 337

  4. 3 || 73 || 3 || 7

  5. 3 || 73 || 37

  6. 37 || 3 || 3 || 7

  7. 37 || 3 || 37

  8. 37 || 337

  9. 373 || 3 || 7

  10. 373 || 37

  11. 3733 || 7

(The only 4 slices of 37337 that fail are the ones containing the composite substrings 33 or 733: 3 || 7 || 33 || 7, 3 || 733 || 7, 37 || 33 || 7, and 3 || 7337.)

2. What OEIS A179919 Counts: Distinct Embedded Primes (111317)

In the OEIS family of sequences (such as A039996 and A179909–A179924), an "embedded prime" is defined as a distinct prime proper substring occurring anywhere within the base-10 representation of the prime.

Under the OEIS definition, three completely different rules apply:

  • The rest of the digits do not need to form primes: You just extract a contiguous block of digits from the number and ignore the digits to the left and right.

  • Duplicates are only counted once: You collect the substrings into a mathematical set of unique prime values.

  • Composite digits like 1 are helpful: Because you don't have to partition the entire number into primes, having the digit 1 (which is not prime and ruins full concatenations) is actually an advantage in A179919 because 1 starts many multi-digit primes (11, 13, 17, 113, 131, 317, etc.).

If we evaluate your number 37337 using the OEIS "embedded primes" rule, it only has 6 embedded primes:

$$\{3, 7, 37, 73, 337, 373, 3733\} \longrightarrow \text{7 primes?}$$

Actually, checking all contiguous proper substrings of 37337:

  • 1-digit: 3, 7 (repeats ignored)

  • 2-digit: 37, 73 (33 is composite)

  • 3-digit: 373, 337 (733 is prime! Wait: 733 is indeed prime!)

  • 4-digit: 3733 (prime), 7337 (7337 = 11 \times 667, composite)

Even with 733 being prime, the set of distinct proper prime substrings of 37337 is \{3, 7, 37, 73, 337, 373, 733, 3733\}, which is only 8 distinct embedded primes (falling short of 11). Furthermore, note that because 733 is prime, 37337 actually has 12 valid prime concatenations in your program (3 || 733 || 7 is also valid!), which is why it passed your MIN_WAYS = 11 threshold (>= 11).

Now compare that to 111317, the first term of OEIS A179919:

  • Under your concatenation program: 111317 has only 1 valid prime concatenation (11 || 13 || 17), because any slice that isolates a single 1 (1 || 11317, 111 || 3 || 17, etc.) fails since 1 is not prime.

  • Under OEIS A179919 (distinct proper prime substrings): Scanning all contiguous substrings of 111317 yields 11 distinct primes:

    1. 1-digit: 3, 7 (2 primes)

    2. 2-digit: 11, 13, 17, 31 (4 primes)

    3. 3-digit: 113, 131, 317 (3 primes)

    4. 4-digit: 1113 (3 \times 371, composite), 1131 (3 \times 377, composite), 1317 (3 \times 439, composite) (0 primes)

    5. 5-digit: 11131 (prime), 11317 (prime) (2 primes)

Summing those unique prime substrings gives 2 + 4 + 3 + 0 + 2 = 11 embedded primes:

$$\{3, 7, 11, 13, 17, 31, 113, 131, 317, 11131, 11317\}$$

Side-by-Side Comparison of the Two Rules


Property

Your Program (Prime Concatenations)

OEIS A179919 (Embedded Primes)

Core Mechanism

Partitions the entire string into adjacent prime blocks (A || B || C).

Extracts any contiguous prime substring from anywhere inside the string.

Unused Digits

Forbidden — every digit must belong to a prime block in the partition.

Allowed — surrounding digits outside the substring are ignored.

Repeated Primes

Counted every time they form a distinct full-string partition.

Ignored — only distinct prime values are counted.

Score for 37337

12 valid full-string prime concatenations.

8 distinct embedded primes (\{3, 7, 37, 73, 337, 373, 733, 3733\}).

Score for 111317

1 valid full-string prime concatenation (11 || 13 || 17).

11 distinct embedded primes (\{3, 7, 11, 13, 17, 31, 113, 131, 317, 11131, 11317\}).

I've gotten Gemini to write a program that accepts any positive integer as input, prime or non-prime, and outputs the concatenated primes as well as the embedded primes. Here is the output for 28323 (permalink):

Analysis for 28323 (Composite)

=============================================

1. PRIME CONCATENATIONS (Total: 4)

   1. 2 || 83 || 2 || 3

   2. 2 || 83 || 23

   3. 283 || 2 || 3

   4. 283 || 23

2. DISTINCT EMBEDDED PRIMES (Total: 5)

   2, 3, 23, 83, 283

I've added this program to my daily number analysis.

Tuesday, 13 October 2026

Beyond 23

The algorithm that I got Gemini to create and that I used in the post 23 Revisited was the result of the following prompt:

Write a program in SageMath that determines all the composite, positive integers in a given range that contain the digits 2 and 3 in ascending order from left to right (but not necessarily consecutively) and whose prime factors also all contain the digits 2 and 3 in ascending order but not necessarily consecutively. The default range can be from 1 to 40000. The output should a table showing number and factors followed by a comma-separated list of the qualifying numbers.

Instead of the prime 23, other prime numbers can be investigated. Composite numbers could be investigated too but this would lead to rather large numbers and so I'll restrict this investigation to prime numbers but I'll increase the range from 1 to one million.

Here are the results for 11 (permalink):

Number       | Prime Factors
------------------------------
110231       | 11, 911
111221       | 11, 10111
112321       | 11, 10211
117821       | 11, 10711
128711       | 11, 11701
129811       | 11, 11801
131153       | 11, 11923
131197       | 11, 11927
171121       | 211, 811
211321       | 11, 19211
231121       | 11, 21011
232111       | 11, 21101
261143       | 113, 2311
351119       | 311, 1129
451121       | 11, 41011
511621       | 11, 46511
781121       | 11, 71011
892111       | 11, 81101

Here are the results for 13 (permalink):

Number       | Prime Factors
------------------------------
13169         | 13, 1013
16913         | 13, 1301
22139         | 13, 131
113269       | 13, 8713
131729       | 13, 10133
131807       | 13, 10139
132703       | 131, 1013
134069       | 13, 10313
136669       | 13, 10513
137069       | 113, 1213
137969       | 13, 10613
138781       | 137, 1013
147013       | 113, 1301
161369       | 13, 12413
169013       | 13, 13001
171301       | 13, 13177
171379       | 13, 13183
172133       | 13, 13241
180713       | 13, 13901
190013       | 139, 1367
211303       | 131, 1613
313469       | 13, 24113
313729       | 13, 24133
313781       | 13, 24137
360139       | 13, 2131
407213       | 313, 1301
413473       | 313, 1321
421369       | 13, 32413
661369       | 313, 2113
797513       | 613, 1301
813397       | 13, 4813
813451       | 613, 1327

Here are the results for 17 (permalink):

Number       | Prime Factors
------------------------------
51731         | 17, 179
117589       | 17, 6917
173009       | 17, 10177
178313       | 17, 617
198917       | 17, 11701
217843       | 179, 1217
291703       | 17, 17159
295817       | 17, 17401
301733       | 17, 17749
308417       | 179, 1723
351713       | 17, 1217
368917       | 17, 21701
506617       | 17, 1753
517021       | 17, 1789
541753       | 317, 1709
717043       | 17, 42179

Here, and finally, are the results for 19 (permalink):

Number       | Prime Factors
------------------------------
19361         | 19, 1019
36119         | 19, 1901
119467       | 193, 619
121943       | 197, 619
193667       | 19, 10193
194629       | 191, 1019
196667       | 193, 1019
251929       | 191, 1319
361019       | 19, 19001
361969       | 19, 19051
366719       | 19, 19301
370519       | 19, 19501
371963       | 19, 19577
376219       | 19, 19801
381947       | 193, 1979
519329       | 191, 2719
601967       | 193, 3119
714419       | 19, 1979
719473       | 19, 1993
752419       | 19, 199
796519       | 419, 1901

I won't continue with primes larger than 23 because really what I want is an algorithm that will identify a sequence of digits that form a prime within a number and then check that the same digit sequence occurs with each of its prime factors. The number being checked is thus composite. Here is a permalink to the program that I've now included in my daily number analysis.

Monday, 18 September 2023

Embedded Primes

The number associated with my diurnal age today, 27197, has the property that it contains nine embedded primes, namely 2, 7, 19, 71, 97, 197, 271, 719 and 2719. This qualifies it for membership in OEIS  A179917 (permalink):


 A179917

Primes with nine embedded primes.                 


The initial members of the sequence are:

11317, 19739, 19973, 21317, 21379, 22397, 22937, 23117, 23173, 23371, 23971, 24373, 26317, 27197, 29173, 29537, 32719, 33739, 33797, 37397, 39719, 51137, 51973, 52313, 53173, 53479, 53719, 57173, 57193, 61379, 61979, 63179, 66173, 82373, 83137, 91373, 93719

This got me thinking about primes that contain no embedded primes. It turns out that there are only 125 such primes in the range up to 100,000. Primes with this property are members of OEIS A033274 (permalink):


 A033274

Primes that do not contain any other prime as a proper substring.           



The initial members of the sequence are:

11, 19, 41, 61, 89, 101, 109, 149, 181, 401, 409, 449, 491, 499, 601, 691, 809, 881, 991, 1009, 1049, 1069, 1481, 1609, 1669, 1699, 1801, 4001, 4049, 4481, 4649, 4801, 4909, 4969, 6091, 6469, 6481, 6869, 6949, 8009, 8069, 8081, 8609, 8669, 8681, 8699, 8849, 9001, 9049, 9091, 9649, 9901, 9949, 10009, 10069, 14009, 14081, 14669, 14699, 14869, 16001, 16069, 16649, 16901, 16981, 18049, 18481, 18869, 40009, 40099, 40609, 40699, 40801, 40849, 44699, 46049, 46099, 46649, 46681, 46901, 48049, 48481, 48649, 48869, 49009, 49069, 49081, 49481, 49669, 49681, 49801, 60091, 60649, 60869, 60901, 64081, 64609, 64849, 64901, 69481, 80669, 80681, 80849, 81001, 81649, 81869, 84869, 86069, 86969, 86981, 88001, 88469, 88801, 90001, 90469, 90481, 90901, 91081, 94009, 94849, 94949, 96001, 98801, 98869, 99469

So there are two types of primes: one contains no prime substrings while the other contains one or more prime substrings. Even five digit numbers can have ten embedded primes, although there are only three of them: 23719, 31379 and 52379. The embedded primes for these numbers are (permalink):
  • 23719: 2, 3, 7, 19, 23, 37, 71, 719, 2371, 3719
  • 31379: 3, 7, 13, 31, 37, 79, 137, 313, 379, 3137
  • 52379: 2, 3, 5, 7, 23, 37, 79, 379, 523, 5237
Primes such as these belong to OEIS A179918:


 A179918



Primes with ten embedded primes. 
                      

The initial members of this sequence are:

23719, 31379, 52379, 111373, 111731, 111733, 112397, 113117, 113167, 113723, 113759, 113761, 115237, 117191, 117431, 121139, 122971, 123113, 123373, 123479, 123731, 124337, 126173, 126317, 127139, 127733, 127739, 127973, 129733, 131171

Of course, the number containing the embedded primes does not need to be prime itself. If we consider only composite numbers, then the following numbers contain nine embedded primes (permalink):

11379, 13137, 13173, 13179, 13197, 13673, 13719, 13731, 13732, 13735, 15237, 17337, 19137, 19733, 21131, 22371, 22373, 22379, 22971, 23113, 23119, 23179, 23313, 23317, 23379, 23479, 23571, 23673, 23733, 23739, 24173, 24673, 25317, 25937, 27113, 27131, 27137, 28317, 28373, 28379, 29371, 29373, 29379, 29397, 29713, 31137, 31197, 31371, 31372, 31375, 31733, 31797, 33719, 33733, 35479, 35937, 36173, 36719, 36733, 36737, 37193, 37197, 37972, 37973, 37975, 37977

There are 66 such composite numbers in the range up to 40,000. Consider 11379, the first number in the sequence. It has the following embedded primes: 3, 7, 11, 13, 37, 79, 113, 137, 379 but is itself composite, factoring to 3 x 3793. This sequence is not listed in the OEIS.

31373 holds the record in the range up to 100,000 with 11 embedded primes, namely 3, 7, 13, 31, 37, 73, 137, 313, 373, 1373 and 3137. It's composite and factorises to 137 x 229. It should be noted that the count of embedded primes is being made without regard to multiplicity. Thus the 3 that occurs three times in 31373 is counted only once. This counting without multiplicity applies to all the previously mentioned sequences.

What about composite numbers that contain no embedded primes. Well, we won't find any numbers containing the digits 2, 3, 5 or 7 and only the digits 0, 1, 4, 6, 8 and 9 will be allowed. There's 1011 in the range up to 40,000 (permalink) but I won't list them here.