from __future__ import division from eulermath import primesieve # Get all the diagonal values for a given (odd) side length def getdiags(side): offset = (side-2)**2 + (side-1) diag = range(offset, side**2+1, side-1) return diag if __name__ == "__main__": ntotalprime = 0 # Starting on side length 1 we have zero primes ndiag = 1 # with only 1 pside = 26507 side = 3 fracprime = 1.00 # Only increment this if we have to print "Pre-computing prime list, please hold on..." primes = set(primesieve(pside**2+1)) while side < 50 or fracprime > 0.1: diag = getdiags(side) nprime = len(primes.intersection(diag)) ntotalprime += nprime ndiag += 4 fracprime = ntotalprime/ndiag print side, fracprime side += 2 print ("Side length for which the ratio of primes is < 10% is: " + repr(side-2))
break return isperm #for n in primes: # pn = n-1 # Euler's totient can be approximated by # phi(n) ~= n-1 # So n/phi(n) ~= n/(n-1) ~= 1 for large n # We want this to be a minimum, so if phi(n) > n would be okay. # But this doesn't happen. So the best we can get is; phi(n) = n # Also note phi(p) = p-1 for prime values # So we only have to test the primes to 10**7 # Unfortunately, none of the primes are permutations of each other... # So start with large n... maxn = 10**7 primes = primesieve(maxn + 1) nprimes = len(primes) #cratio = (10,1,1) ratios = [] for n in primes: pn = n - 1 if checkperm(n,pn): print "permutation found %d %d" % (n,pn) #if n/pn < cratio[0]: # cratio = (n/pn,n,pn) #print "New low value! (ratio,prime,phi(n)) = (%f,%d,%d)" % cratio cratio = (n/pn,n,pn) print "Appending: (ratio,prime,phi(n)) = (%f,%d,%d)" % cratio ratios.append(cratio) #print "%f%% complete" % (n/maxn*100) #print "%f%% complete" % (n/nprimes*100)
newprime[ind] = cint # Check that the length is the same if len(newprime) == len(int2array(array2int(newprime))): subgroup.append(array2int(newprime)) pgroup.append(subgroup) return pgroup if __name__ == "__main__": fam_test_size = 6 # We have the solutions for a 6 and 7 family size, # make sure we get these back print "Printing primes, family size, and minimum prime in family" print "Also printing full familly for check" for ndig in range(2, 9): # We want these two to be discrete primes = list(primesieve(10**ndig)) primescheck = set(primesieve(10**ndig)) # print "Primes" # print primescheck for prime in primes: testlists = replaceprime(prime) # print "After replacement:" # print testlists for test in testlists: primes_in_test = primescheck.intersection(test) # print primes_in_test famsize = len(primes_in_test) # print "Prime and family size:" if famsize >= fam_test_size: fam_test_size += 1 print