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

Home > Numbers
Change the First Digit, Get Three Primes (Posted on 2023-07-17) Difficulty: 3 of 5
A 5-digit base-N prime number P is such that we will obtain three other prime numbers by changing its first digit.

Determine the minimum value of N.

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 Solution | Comment 1 of 2
For N = base 6, 10001 (1297 in decimal) makes 3 other primes if the first digit is changed.
base 6 10001
base 6   ['10001', '20001', '30001', '50001']
decimal [1297, 2593, 3889, 6481]

----------------
def base2base(n,a,b):
    """ input n which is a string of the number to be changed
    'a' is an integer representing the current base
    to be changed to base b 
    """
    def dec2base(i,base):
        """ INPUT integer in base 10, return string 
        of Base base equivalent. """
        convertString = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
        if i < base:
            return convertString[i]
        else:
            return dec2base(i//base,base) + convertString[i%base]
    if a == 10:
        return dec2base(int(n),b)
    if b == 10:
        return int(str(n),a)
    elif b != 10:
        return base2base(int(str(n),a),10,b)
    
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

base = 6

digits = [str(i) for i in range(base)]
bot = base**(4)
top = base**5
primes = [base2base(n, 10, base) for n in range(bot,top) if isprime(n)]

for p in primes:
    count = 0
    baselist = []
    decilist = []
    for d in digits:
        test = d + p[1:]
        if test in primes:
            count += 1
            baselist.append(test)
            decilist.append(base2base(test,base,10))
    if count >= 4:
        print('base', base, p)
        print(baselist)
        print(decilist)

  Posted by Larry on 2023-07-17 09:36:55
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 (12)
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