Showing posts with label emirpimes. Show all posts
Showing posts with label emirpimes. Show all posts

Friday, 20 March 2026

Concatenating Emirpimes

Emirpimes have the property that they remain semiprimes when reversed. Thus 15 = 3 x 5 becomes 51 when the digits are reversed and 51 = 3 x 17 which is also a semiprime. What happens to the emirpimes if it is concatenated with its reverse. Does it remain a semiprime? In the case 15, this leads to 1551 = 3 x 11 x 47 which is a sphenic number and not a semiprime. The first such emirpimes is 94 because 9449 = 11 x 859 is a semiprime. In fact all such emirpimes will have 11 as a factor. Here is Gemini's explanation:

The reason no numbers starting with the digit 2 appear in your output comes down to two absolute mathematical rules regarding divisibility: the behavior of even-length palindromes and the properties of even numbers.

When you concatenate a number that begins with 2 with its exact reverse, you are guaranteeing that the resulting number will have at least three prime factors, which automatically disqualifies it from being a semiprime.

Here is the step-by-step breakdown of exactly why this happens:

1. The Concatenated Number is Always an Even-Length Palindrome

When you take any number string and append its exact reverse (e.g., $n = 26$, $rev = 62$, resulting in 2662), you create a perfect mirror image. Because you are doubling the number of digits, the resulting palindrome will always have an even length.

There is a fundamental rule in number theory: Every palindrome with an even number of digits is divisible by 11. Because your program only evaluates these concatenated mirror-images, every single number evaluated in that final step has 11 as one of its prime factors.

2. The Resulting Number Always Ends in 2

If your original number ($n$) starts with the digit 2, its reverse will naturally end with the digit 2. When you concatenate the original number with its reverse, the very last digit of the new string will be the last digit of the reverse.

For example:

  • Original: 215

  • Reverse: 512

  • Concatenation: 215512

Because the concatenated number ends in 2, it is an even number. This means 2 is definitively another prime factor of the concatenated number.

3. The Factor Count Exceeds the Semiprime Limit

By definition, a semiprime must have exactly two prime factors (e.g., $p_1 \times p_2$).

If you start with a number beginning with 2, we have already established that the final concatenated number is divisible by both 11 and 2. Therefore, the number is a multiple of 22.

For a multiple of 22 to be a semiprime, the number would have to be exactly 22 itself (where 2 and 11 are the only factors). For your program to generate 22, the original number would have to be 2, and the reverse would have to be 2. This fails on multiple fronts:

  • 2 is a prime number, not a semiprime.

  • Your code explicitly filters out palindromes (n != rev_n), so it would ignore 2 anyway.

Any valid concatenated number your program produces that begins with a 2 will be much larger than 22 (the smallest would be 2442, derived from $n=24$). Therefore, its prime factorization will always look like $2 \times 11 \times x$, containing at least three prime factors.

Broader Implications

Because of these exact same mathematical rules, your output will also never contain numbers starting with:

  • 4, 6, or 8: The resulting concatenations would all end in an even number, meaning they are divisible by 2 and 11, resulting in too many factors.

  • 5: The resulting concatenation would end in a 5, meaning it is divisible by 5 and 11, again resulting in too many factors.

The only numbers that can mathematically survive this final semiprime check are those starting with 1, 3, 7, or 9.

Here is the list of emirpimes that satisfy in the range up to 40,000 (permalink):

=== Emirpime Concatenation Statistics ===

Range evaluated: 1 to 40000

1. Semiprimes: 9790 (24.47% of the range)

2. Emirpimes: 3450 (8.62% of the range)

3. Successful Emirpimes: 476 (1.19% of the range)

94, 115, 169, 185, 341, 355, 394, 398, 766, 794, 923, 926, 955, 985, 1027, 1046, 1141, 1174, 1195, 1202, 1238, 1247, 1306, 1343, 1366, 1382, 1417, 1418, 1466, 1642, 1658, 1703, 1714, 1754, 1757, 1769, 1843, 1891, 1915, 1927, 1985, 3047, 3062, 3071, 3091, 3097, 3098, 3103, 3151, 3166, 3227, 3317, 3385, 3403, 3473, 3599, 3635, 3646, 3653, 3785, 3817, 3866, 3949, 3959, 3979, 3983, 7051, 7058, 7082, 7094, 7165, 7169, 7183, 7186, 7223, 7226, 7235, 7274, 7291, 7318, 7346, 7354, 7367, 7403, 7522, 7637, 7655, 7663, 7715, 7754, 7795, 7849, 7855, 7981, 9121, 9242, 9259, 9346, 9427, 9569, 9578, 9593, 9599, 9617, 9727, 9755, 9809, 9946, 9953, 9983, 9997, 10033, 10085, 10129, 10195, 10261, 10342, 10345, 10462, 10466, 10483, 10517, 10541, 10546, 10558, 10637, 10673, 10705, 10805, 11006, 11141, 11147, 11249, 11302, 11306, 11363, 11366, 11539, 11563, 11591, 11641, 11651, 11653, 11654, 11714, 11723, 11851, 11893, 11917, 11945, 12001, 12013, 12067, 12127, 12146, 12199, 12202, 12217, 12283, 12317, 12361, 12367, 12439, 12458, 12494, 12509, 12674, 12718, 12751, 12758, 12761, 12851, 12877, 12913, 12937, 13102, 13106, 13133, 13142, 13193, 13273, 13322, 13373, 13391, 13459, 13529, 13637, 13739, 13742, 13787, 13817, 13934, 13993, 14015, 14111, 14171, 14213, 14219, 14242, 14261, 14273, 14291, 14318, 14359, 14486, 14501, 14611, 14642, 14647, 14765, 14786, 14834, 14999, 15094, 15157, 15335, 15362, 15389, 15403, 15623, 15658, 15779, 15781, 15793, 15815, 15863, 15874, 15893, 15989, 16003, 16123, 16129, 16153, 16207, 16265, 16331, 16334, 16367, 16387, 16489, 16507, 16859, 16865, 16909, 16969, 17083, 17218, 17261, 17305, 17311, 17441, 17503, 17533, 17611, 17614, 17662, 17687, 18035, 18155, 18463, 18482, 18547, 18613, 18623, 18686, 18689, 18695, 18794, 18806, 18847, 18937, 19015, 19165, 19217, 19246, 19286, 19297, 19331, 19337, 19354, 19358, 19405, 19445, 19579, 19585, 19607, 19637, 19667, 19757, 19858, 19882, 19931, 19969, 30043, 30143, 30182, 30407, 30413, 30437, 30574, 30605, 30607, 30641, 30662, 30731, 30754, 30755, 30779, 30826, 30854, 30865, 30886, 30913, 30991, 30994, 30995, 31127, 31138, 31282, 31342, 31399, 31453, 31807, 31843, 31853, 31946, 31969, 32066, 32071, 32137, 32138, 32177, 32366, 32455, 32458, 32501, 32593, 32602, 32663, 32666, 32765, 32842, 32845, 32891, 33109, 33253, 33257, 33445, 33458, 33559, 33593, 33737, 33991, 34073, 34154, 34169, 34186, 34187, 34205, 34379, 34382, 34409, 34477, 34571, 34598, 34657, 34723, 34745, 34802, 34831, 34907, 34999, 35078, 35135, 35137, 35147, 35173, 35215, 35263, 35269, 35285, 35471, 35522, 35545, 35567, 35723, 35773, 35779, 35813, 35881, 36029, 36035, 36065, 36139, 36143, 36203, 36227, 36311, 36422, 36427, 36446, 36481, 36503, 36535, 36614, 36626, 36631, 36649, 36679, 36733, 36734, 36745, 36794, 36802, 37006, 37031, 37034, 37099, 37153, 37157, 37231, 37331, 37358, 37399, 37438, 37457, 37477, 37487, 37498, 37514, 37574, 37601, 37739, 37834, 37837, 37931, 37946, 37958, 38174, 38209, 38245, 38401, 38413, 38414, 38477, 38497, 38534, 38585, 38597, 38635, 38719, 38785, 38806, 38951, 39037, 39127, 39142, 39205, 39253, 39265, 39289, 39449, 39518, 39523, 39653, 39797, 39826, 39871, 39898, 39899, 39911, 39931, 39947, 39958, 39959, 39977

Monday, 15 December 2025

Emirpimes In Bases Greater Than 10

Why stop at bases between 2 and 9? I prompted Gemini again:

Can this program be modified so that it can investigate numbers in bases from 11 to 16? I know this is more difficult because of the necessary use of letters as well as the digits from 0 to 9.  

The program that it came up with works in bases from 2 to 36 which is impressive. I'll include the code and Gemini's explanation of it after the tables that cover bases of 11, 12, 13, 14, 15 and 16.

BASE 11


Table 1: permalink

BASE 12


Table 2: permalink

BASE 13


Table 3: permalink

BASE 14


Table 4: permalink

BASE 15


Table 5: permalink

BASE 16


Here is the code and what Gemini had to say about it. 

Yes, this can definitely be done. The core logic of the mathematics (checking primes and reversing lists of numbers) remains exactly the same. The only complexity is visual: we need to translate the internal numbers (10, 11, 12, etc.) into their representative symbols (A, B, C, etc.) so they are readable in the output.

Here is the upgraded program. It now includes a DIGIT_MAP to handle bases up to 16 (and actually up to 36, if you wanted to go higher).

The Upgraded Python Program (Bases 2–16)

Python
# ==========================================
#  CONFIGURATION (User Inputs)
# ==========================================
SEARCH_BASE = 16          # Supports bases 2 through 16
SEARCH_RANGE = (1, 60000) # Range to search [start, end]

# ==========================================
#  CORE FUNCTIONS
# ==========================================

# Standard mapping for bases > 10
DIGIT_MAP = "0123456789ABCDEF"

def to_base(n, b):
    """Converts an integer n to a list of digit values in base b."""
    if n == 0:
        return [0]
    digits = []
    while n:
        digits.append(int(n % b))
        n //= b
    return digits[::-1]

def from_base(digits, b):
    """Converts a list of digit values in base b back to an integer."""
    n = 0
    for d in digits:
        n = n * b + d
    return n

def get_reversed_val(n, b):
    """Returns the integer value of n with its digits reversed in base b."""
    digits = to_base(n, b)
    # We reverse the list of values (e.g. [1, 15] becomes [15, 1])
    return from_base(digits[::-1], b)

def is_prime(n):
    """Efficient primality test."""
    if n <= 1: return False
    if n <= 3: return True
    if n % 2 == 0 or n % 3 == 0: return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

def get_semiprime_factors(n):
    """
    Returns [p, q] if n is a semiprime.
    Returns None otherwise.
    """
    factors = []
    d = 2
    temp = n
    # Optimization: limit search to sqrt(temp)
    while d * d <= temp:
        while temp % d == 0:
            factors.append(d)
            temp //= d
            if len(factors) > 2: 
                return None
        d += 1
    if temp > 1:
        factors.append(temp)
    
    if len(factors) == 2:
        return factors
    return None

def format_in_base(n, b):
    """
    Returns string representation of n in base b using 0-9 and A-F.
    """
    digits = to_base(n, b)
    # Map integer values (e.g., 10) to characters (e.g., 'A')
    return "".join(DIGIT_MAP[d] for d in digits)

# ==========================================
#  MAIN EXECUTION
# ==========================================

print(f"Searching for special Emirpimes in Base {SEARCH_BASE} between {SEARCH_RANGE}...")
print(f"Format: Base 10 | Base {SEARCH_BASE} | Factors (Base {SEARCH_BASE}) | Reversed (Base {SEARCH_BASE}) | Rev Factors (Base {SEARCH_BASE})")
print(f"{'-'*110}")

count = 0
start, end = SEARCH_RANGE

for n in range(start, end + 1):
    # 1. Check if semiprime
    factors = get_semiprime_factors(n)
    if not factors:
        continue
    
    p, q = factors[0], factors[1]
    
    # 2. Get reversed values in the target base
    n_rev_val = get_reversed_val(n, SEARCH_BASE)
    p_rev_val = get_reversed_val(p, SEARCH_BASE)
    q_rev_val = get_reversed_val(q, SEARCH_BASE)
    
    # 3. Check Condition 1: Factors must be 'Emirps' in this base
    # (Reversed factors must be prime)
    if not (is_prime(p_rev_val) and is_prime(q_rev_val)):
        continue
        
    # 4. Check Condition 2: The "Special" Multiplication Property
    # Rev(n) == Rev(p) * Rev(q)
    if n_rev_val == (p_rev_val * q_rev_val):
        
        # Prepare output strings using the Alpha-Numeric formatter
        n_str = format_in_base(n, SEARCH_BASE)
        p_str = format_in_base(p, SEARCH_BASE)
        q_str = format_in_base(q, SEARCH_BASE)
        
        n_rev_str = format_in_base(n_rev_val, SEARCH_BASE)
        p_rev_str = format_in_base(p_rev_val, SEARCH_BASE)
        q_rev_str = format_in_base(q_rev_val, SEARCH_BASE)
        
        factors_str = f"{p_str} x {q_str}"
        rev_factors_str = f"{p_rev_str} x {q_rev_str}"

        # Print formatted columns
        print(f"{n:<10} | {n_str:<10} | {factors_str:<20} | {n_rev_str:<20} | {rev_factors_str:<20}")
        count += 1

print(f"{'-'*110}")
print(f"Found {count} special emirpimes in Base {SEARCH_BASE}.")

Key Improvements

  1. DIGIT_MAP = "0123456789ABCDEF": This string acts as a lookup table. If a digit value is 15, the code looks at index 15 and retrieves 'F'.

  2. format_in_base: This function was rewritten to use the lookup table, ensuring that any number from 10 to 15 is printed as a letter.

  3. Universal Logic: This version works for any base from 2 to 16 without needing further changes. You simply change SEARCH_BASE = 16, 12, or 8 at the top.

Example: What to expect in Base 16 (Hexadecimal)

If you run this with SEARCH_BASE = 16, you might see results involving the digit 'A' (10) or 'C' (12), provided the "no carrying" rule is met.

  • Example: If we had $13 \times 13 = 169$ in Base 10, in Base 16 this is $D \times D = A9$.

  • Since $D$ (13) is a single digit, reversing it changes nothing, so it acts like a palindrome.

  • However, finding multi-digit primes in Base 16 that don't "carry" when multiplied is harder because the "digits" are larger, but the slots fill up differently.