def get_prime_list_true_prime(max_num): # need to be at least 2 assert(max_num >= 1) init_list = [] for i in range(2, max_num + 1): init_list.append(i) # print init_list j = 0 new_list = init_list new_list_len = len(new_list) sqrt_of_max_num = int(math.sqrt(max_num)) while(1): checkNum = new_list[j] # show the progress of each iteration # print 'j = %5d checkNum %5d, new_list_len %5d'%(j, checkNum, new_list_len) # we only need to sieve up to sqrt(max_num) if (checkNum > sqrt_of_max_num): break new_list = erato_siev_one_round(new_list, checkNum) # print new_list j = j+1 new_list_len = len(new_list) if(new_list_len <= j): break print 'number of primes: %d'%(new_list_len) # print 'prime list:', new_list return new_list
def get_num_count_in_M_set_not_divisible_by_prime_less_than_xi(M_set, xi): # need to be at least 2 target_num = len(M_set) assert target_num >= 1 prime_list = get_prime_list(xi) init_list = deepcopy(M_set) # print init_list j = 0 # construct initial list. Initial list may include [1] at beginning, we skip it. if init_list[0] == 1: new_list = init_list[1:] else: new_list = init_list while 1: checkNum = prime_list[j] # show the progress of each iteration # print 'j = %5d checkNum %5d, new_list_len %5d'%(j, checkNum, new_list_len) new_list = erato_siev_one_round(new_list, checkNum) # print new_list j = j + 1 if j == len(prime_list): break sift_left_cnt = len(new_list) print "number not_divisible_by_prime_less_than_xi: %d \n" % (sift_left_cnt) # print 'number not_divisible_by_prime_less_than_xi:', new_list, '\n' return sift_left_cnt