View Single Post
Old 2020-06-10, 21:15   #256
Dylan14
 
Dylan14's Avatar
 
"Dylan"
Mar 2017

7628 Posts
Default

Quote:
Originally Posted by carpetpool View Post
Also another interesting problem if anyone's interested:

Twin primes of the form k*b^n+-1 with k < n -->
I wrote a Python script to drive the sieving:
Code:
#script to automate sieving for small twins of the form k*b^n+/-1, where
#k < n

import subprocess

#set parameters
b = input("Enter a base (not a perfect power):")
minn = input("Enter the minimum n to test:")
maxn = input("Enter the maximum n to test:")

#check that minn is not 1. Otherwise the only k we would test is k = 0, but
#0*b^1+/-1 = +/-1 for all b. And +1 and -1 are not prime (by definition).
if int(minn) == 1:
    raise ValueError("n = 1 implies we have to test k = 0 only, and 0*b^1+/-1 is either 1 or -1, which are not prime.")
else:    
    n = int(minn)
while n <= int(maxn):
    #we'll set the max sieve depth via if/else statements, 
    #we can adjust this if needed
    if n <= 5000:
        sievedepth = 1000000
    elif n <= 10000:
        sievedepth = 5000000
    elif n <= 20000:
        sievedepth = 25000000
    elif n <= 40000:
        sievedepth = 100000000
    else:
        sievedepth = 250000000
    #calculate maxk, which is n-1
    maxk = n-1
    #for n = 2 we have to be a bit more careful. The only meaningful k is 1. But twinsieve gives a error: kmax has to be greater than kmin.
    #so we will tell the user that he'll need to test it himself with pfgw.
    if n == 2:
        print("n = 2 yields an error in twinsieve. You'll need to test " + str(b) + "^" + str(n) + "+/-1 yourself in LLR or pfgw.")
        n = n + 1
    else:
        #now call subprocess.
        subprocess.run(["twinsieve", "-P", str(sievedepth), "-k", "1", "-K", str(maxk), "-b", str(b),"-n", str(n)])
        n = n+1
Using this, I tested b = 20 to n = 2k. I found the following twin primes:
Code:
3*20^8+1 
3*20^8-1
105*20^152+1
105*20^152-1
24*20^36+1
24*20^36-1
60*20^68+1
60*20^68-1
3*20^69+1
3*20^69-1
Dylan14 is offline   Reply With Quote