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

Home > Numbers
Change the First Digit, Get Two Primes (Posted on 2023-01-19) Difficulty: 3 of 5
Determine the minimum value of a 100- digit prime number such that we will obtain two other prime numbers by changing its leftmost digit.

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 2 of 2 |
Program output (edited for readability) finds these three 100-digit primes:
1000 ... 00076353,
5000 ... 00076353,
7000 ... 00076353

The problem did not ask for this, but by changing a "1" to a "2" in the following line of code:
if len(primeTriplets) >1:

... we get the first 100-digit prime for which changing the first digit obtains three additional primes:
1000 ... 04817529,
4000 ... 04817529,
5000 ... 04817529,
7000 ... 04817529

------  Python with use of sympy library  ------
import sympy as sp
big =  int('1' + '0' * 99)
first = sp.nextprime(big)
thisPrime = first
digits = [i for i in range(1,10)]
found = False
solutions = []
while not found:
    primeTriplets = []
    stp = str(thisPrime)
    dfirst = stp[0]
    rest = stp[1:]
    nfirst = int(dfirst)
    testDigits = [i for i in digits if i != nfirst]
    for d in testDigits:
        test = int(str(d) + rest)
        if sp.isprime(test):
            primeTriplets.append(test)
    if len(primeTriplets) >1:
        primeTriplets.insert(0,thisPrime)
        solutions.append(primeTriplets)
        print(primeTriplets)
        found = True

    nextP = sp.nextprime(thisPrime)
    thisPrime = nextP
  Posted by Larry on 2023-01-19 13:11:50
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 (9)
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