All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Semiprimes and Emirps (Posted on 2023-01-14) Difficulty: 3 of 5
Determine the total number of semiprimes below 2023, that are immediately followed by an emirp.

For example, 22 is a semiprime which is immediately followed by 23. But 23 is NOT an emirp, since 32 is composite.

List all valid pairs in conformity with the provisions of the problem.

*** Computer program/ excel solver aided methods are welcome, but a semi-analytic methodology is preferred.

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Computer solution | Comment 1 of 5
Computer solution:
106 107
166 167
178 179
346 347
358 359
982 983
1282 1283
1438 1439
1486 1487
1522 1523
1618 1619

The following were excluded due to the second number being a palindrome, and emirps are primes which are also primes (but a different prime) when reversed, so no palindromes:
4 5
6 7
10 11
382 383

-------
def isprime(n):
    '''check if integer n is a prime'''
    n = abs(int(n))
    if n < 2:
        return False
    if n == 2:
        return True    
    if not n & 1:
        return False
    for x in range(3, int(n**0.5)+1, 2):
        if n % x == 0:
            return False
    return True

def issemiprime(n):
    top = 1 + int(n**.5)
    for i in range(2,top+1):
        if isprime(i):
            dividend = n/i
            if (dividend)%1 == 0:
                if isprime(int(dividend)):
                    return True
    return False

def isemirp(n):
    backwards = int(str(n)[::-1])
    if isprime(n) and isprime(backwards) and n != backwards:
        return True
    return False


primes = [i for i in range(2024) if isprime(i)]
semiprimes = [i for i in range(2024) if issemiprime(i)]
emirps = [i for i in range(2024) if isemirp(i)]

pairs = []
for i in range(2024):
    if issemiprime(i) and isemirp(i+1):
        print(i,i+1)
        pairs.append([i,i+1])
  Posted by Larry on 2023-01-14 10:09:25
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information