def find_circ_primes(N): c_primes = [] potential_primes_1 = [2, 3] ii = 1 while 6 * ii <= (N): potential_primes_1.append(6 * ii - 1) potential_primes_1.append(6 * ii + 1) ii += 1 potential_primes_2 = [2, 5] for kk in potential_primes_1: if mwmath.circ_digit_check(kk) and mwmath.is_prime(kk): potential_primes_2.append(kk) for jj in potential_primes_2: new_p = jj p_check = True rotations = mwmath.count_digits(jj) - 1 while p_check and rotations > 0: new_p = mwmath.rotate_digits(new_p) p_check = mwmath.is_prime(new_p) rotations -= 1 if p_check: c_primes.append(jj) return c_primes
def find_circ_primes(N): c_primes = [] potential_primes_1 = [2,3] ii = 1 while 6*ii<=(N): potential_primes_1.append(6*ii-1) potential_primes_1.append(6*ii+1) ii+=1 potential_primes_2 = [2,5] for kk in potential_primes_1: if mwmath.circ_digit_check(kk) and mwmath.is_prime(kk): potential_primes_2.append(kk) for jj in potential_primes_2: new_p = jj p_check = True rotations = mwmath.count_digits(jj)-1 while p_check and rotations>0: new_p = mwmath.rotate_digits(new_p) p_check=mwmath.is_prime(new_p) rotations-=1 if p_check: c_primes.append(jj) return c_primes
def find_prime_ratio(spiral,previous_p): prime_elements = 0 for ii in spiral[len(spiral)-4:]: if mwmath.is_prime(ii): prime_elements+=1 return [prime_elements+previous_p,1.0*(prime_elements+previous_p)/len(spiral)]
def main(N1,N2): max_x = 1 max_D = 1 for ii in range(N1,N2+1): if not mwmath.is_prime(ii): continue else: temp = sold_quad_Dio_2(ii,ii*10000000) #print temp if temp[0]>max_x: max_x = temp[0] max_D = ii return max_D
def build_prime_list(n): potential_primes=[2,3] ii = 1 while 6*ii<=(n): potential_primes.append(6*ii-1) potential_primes.append(6*ii+1) ii+=1 prime_list=[] for jj in potential_primes: if mwmath.is_prime(jj): prime_list.append(jj) return prime_list
def build_prime_list(n): potential_primes = [2, 3] ii = 1 while 6 * ii <= (n): potential_primes.append(6 * ii - 1) potential_primes.append(6 * ii + 1) ii += 1 prime_list = [] for jj in potential_primes: if mwmath.is_prime(jj): prime_list.append(jj) return prime_list
while True: if a**k % n == 1: return k k += 1 potential_primes = [] ii = 1 while 6 * ii <= (1000): potential_primes.append(6 * ii - 1) potential_primes.append(6 * ii + 1) ii += 1 primes = [] for p_ii in potential_primes: if mwmath.is_prime(p_ii): primes.append(p_ii) primes.remove(5) max_length = 1 max_p = 1 for p in primes: order = mult_order_mod_n(10, p) print str(p) + ": " + str(order) if order > max_length: max_length = order max_p = p print max_p
s = time.time() N = 100000000 potential_primes = [2, 3] ii = 1 while 6 * ii <= (N): potential_primes.append(6 * ii - 1) potential_primes.append(6 * ii + 1) ii += 1 w_file = open("primes_to_100000000.txt", "w") for ele in potential_primes: if mwmath.is_prime(ele): w_file.write(str(ele) + "\n") w_file.close() r_file = open("primes_to_100000s000.txt", "r") def check_prime(n, f): return str(n) in f.read() s = time.time() print check_prime(5, r_file) print check_prime(51, r_file) print check_prime(53234239, r_file)
s = time.time() N = 100000000 potential_primes = [2,3] ii = 1 while 6*ii<=(N): potential_primes.append(6*ii-1) potential_primes.append(6*ii+1) ii+=1 w_file = open("primes_to_100000000.txt","w") for ele in potential_primes: if mwmath.is_prime(ele): w_file.write(str(ele)+"\n") w_file.close() r_file = open("primes_to_100000s000.txt","r") def check_prime(n,f): return str(n) in f.read() s = time.time() print check_prime(5,r_file) print check_prime(51,r_file) print check_prime(53234239,r_file)
import mwmath import time s = time.time() n = 10000 potential_primes = [2, 3] ii = 1 while 6 * ii <= (n): potential_primes.append(6 * ii - 1) potential_primes.append(6 * ii + 1) ii += 1 prime_list = [] for jj in potential_primes: if mwmath.is_prime(jj): prime_list.append(jj) new_p = 37 digits = mwmath.get_digits(new_p) check = True for digit in digits: if (digit % 2 == 0): check = False print "Contains an even digit" #try to truncate from right while check: if len(mwmath.get_digits(new_p)) == 1:
import math import mwmath import time s = time.time() print mwmath.is_pandigital(1234) print mwmath.is_pandigital(12343) print mwmath.is_pandigital(12) print mwmath.is_pandigital(4312) potential_primes = [] nn = 10000000 ii = 1000000 while 6*ii<=(nn): potential_primes.append(6*ii-1) potential_primes.append(6*ii+1) ii+=1 pan_list = [] for ele in potential_primes: if mwmath.is_pandigital(ele): if mwmath.is_prime(ele): pan_list.append(ele) print max(pan_list) print time.time()-s
import math import mwmath import time s = time.time() n = 100 potential_primes = [2,3] ii = 1 while 6*ii<=n potential_primes.append(6*ii-1) potential_primes.append(6*ii+1) ii+=1 prime_list = [] for jj in potential_primes if mwmath.is_prime(jj): prime_list.append(jj) print prime_list print time.time()-s
k = 1 while True: if a**k%n==1: return k k+=1 potential_primes = [] ii = 1 while 6*ii<=(1000): potential_primes.append(6*ii-1) potential_primes.append(6*ii+1) ii+=1 primes = [] for p_ii in potential_primes: if mwmath.is_prime(p_ii): primes.append(p_ii) primes.remove(5) max_length = 1 max_p = 1 for p in primes: order = mult_order_mod_n(10,p) print str(p)+": "+str(order) if order>max_length: max_length = order max_p = p print max_p
s = time.time() limit = 10000 potential_primes_1 = [2, 3] ii = 1 while 6 * ii <= limit: potential_primes_1.append(6 * ii - 1) potential_primes_1.append(6 * ii + 1) ii += 1 potential_primes_2 = [2, 5] print time.time() - s for kk in potential_primes_1: if mwmath.is_prime(kk): potential_primes_2.append(kk) jj = 9 check = True while jj < limit and check: if jj in potential_primes_2: jj += 2 else: for m in potential_primes_2: if m > jj: print jj check = False break else: diff = (jj - m) / 2
def is_prime(n): return mwmath.is_prime(n)
s = time.time() limit = 10000 potential_primes_1 = [2,3] ii = 1 while 6*ii<=limit: potential_primes_1.append(6*ii-1) potential_primes_1.append(6*ii+1) ii+=1 potential_primes_2 = [2,5] print time.time()-s for kk in potential_primes_1: if mwmath.is_prime(kk): potential_primes_2.append(kk) jj = 9 check = True while jj<limit and check: if jj in potential_primes_2: jj+=2 else: for m in potential_primes_2: if m>jj: print jj check=False break else: diff = (jj-m)/2
import math import mwmath import time s = time.time() print mwmath.is_pandigital(1234) print mwmath.is_pandigital(12343) print mwmath.is_pandigital(12) print mwmath.is_pandigital(4312) potential_primes = [] nn = 10000000 ii = 1000000 while 6 * ii <= (nn): potential_primes.append(6 * ii - 1) potential_primes.append(6 * ii + 1) ii += 1 pan_list = [] for ele in potential_primes: if mwmath.is_pandigital(ele): if mwmath.is_prime(ele): pan_list.append(ele) print max(pan_list) print time.time() - s