def get_prime(n): # Для x >= 17 доказано следующее неравенство касательно функции распределения простых чисел - Pi(x): # x / ln(x) < Pi(x) < 1.25506 * x / ln(x), воспользуемся этим и сформируем диапозон чисел # для просеивания в решете Эратосфена достаточной длины, но в то же время без избыточности # (для получения более оптимального алгоритма). # Нам нужно решать обратную задачу: по известной Pi(x) найти супремум для x, # для него известна и доказана следующая верхняя грань (для n >= 6): x < n * ln(n) + n * ln(ln(n)) # Таким образом, на выходе мы получим простые числа в количестве, гарантированно превышающем изначально заданное if n >= 6: primes = eratosthenes(get_numbers_supremum(n)) else: # На 17 чисел приходится 6 простых, поэтому в решето пойдут лишь они primes = eratosthenes(17) return primes[n - 1]
def __init__(self, debug): self.ignore = Ignore(modules = [], dirs = [os.path.dirname(__file__), os.path.abspath(os.path.join(os.path.dirname(__file__), "../../common_modules")), "/usr/lib/python2.6", "/usr/lib/python2.7"]) self.SI = None self.trace_func = self._Tracer self.no_symbolic = debug self.unique_op_map = {} self.execution_context = None self.known_code_blocks = {} self.parser = ByteCodeParser(self) self.prime_generator = eratosthenes() self.arguments = {} self.inside_tracing_code = True self.function_to_be_traced = None
def __init__(self, debug): # this line is very important; if the ignore directories are not correctly set # (especially PYTHONHOME), the whole thing silently fails to work. Should make # more robust in future self.ignore = Ignore(modules = [], dirs = [os.path.dirname(__file__), os.environ["PYTHONHOME"]]) self.SI = None self.trace_func = self._Tracer self.no_symbolic = debug self.unique_op_map = {} self.execution_context = None self.known_code_blocks = {} self.parser = ByteCodeParser() self.prime_generator = eratosthenes() self.arguments = {} self.inside_tracing_code = True self.function_to_be_traced = None
def factor(N): """Factor a integer number N. >>> factor(1) defaultdict(<class 'int'>, {1: 1}) >>> factor(2) defaultdict(<class 'int'>, {2: 1}) >>> factor(4) defaultdict(<class 'int'>, {2: 2}) >>> factor(41) defaultdict(<class 'int'>, {41: 1}) >>> factor(38556) defaultdict(<class 'int'>, {17: 1, 2: 2, 3: 4, 7: 1}) >>> factor(1307674368000) defaultdict(<class 'int'>, {17: 1, 2: 2, 3: 4, 7: 1}) """ sqrt_n = int(math.sqrt(N)) factors = defaultdict(int) if N == 1: factors[1] = 1 return factors # Find the primes that can be factors primes = eratosthenes(N) canstop = False for p in primes: while N % p == 0: factors[p] += 1 N /= p if p > sqrt_n: canstop = True if canstop: break return factors
def main(local_argv): """ local_argv is the argument list, progrom name is first arugment this function prints the fibonacci list calcuated by the command line argument n """ if len(local_argv) != 2: print("must add one and only one command argument, , exit ") return argument_n = int( local_argv[1]) #remember, this is the 2nd argument in command line if argument_n <= 0: print("please input an pistive interger number, exit") return retList = eratosthenes.eratosthenes(argument_n) return retList
def __init__(self, debug): self.ignore = Ignore(modules=[], dirs=[ os.path.dirname(__file__), os.path.abspath( os.path.join(os.path.dirname(__file__), "../../common_modules")), "/usr/lib/python2.6", "/usr/lib/python2.7" ]) self.SI = None self.trace_func = self._Tracer self.no_symbolic = debug self.unique_op_map = {} self.execution_context = None self.known_code_blocks = {} self.parser = ByteCodeParser(self) self.prime_generator = eratosthenes() self.arguments = {} self.inside_tracing_code = True self.function_to_be_traced = None
def generateTestData(max): inp = [i for i in range(2, max)] inpbitlist = [transBitList(x, max) for x in inp] primelist = eratosthenes.eratosthenes(inp) ans = [transBool(i in primelist) for i in inp] return [inp, inpbitlist, ans]
return [N] for c in n_str: if c in "024568": return None res = [] cur = n_str for i in range(len(n_str)): res.append(int(cur)) cur = cur[-1] + cur[:-1] return res N = 1000000 primes = eratosthenes(N) print(len(primes)) assert N > 1 circ_primes = [] for p in primes: circulars = gen_circular(p) if circulars is None: continue print(p) print(circulars) prime_test = list(map(lambda x: x in primes, circulars)) print(prime_test) if all(prime_test): circ_primes.append(p)