def pi_2(n: int) -> int: ns = [ primepi(n / prime(i)) - i + 1 for i in range(1, primepi(sqrt(n)) + 1) ] return sum(ns)
def DpList(n): D = [] for p in sy.primerange(1, n + 3): m = 1 while (sy.primepi(p - m) == sy.primepi(p + m) - 1): m = m + 1 D.append(m - 1) return D
def opt_factorial_factors(factorial_n): prime_factors = {} for i in xrange(1, sympy.primepi(factorial_n) + 1): p = sympy.prime(i) k = prime_exponent(factorial_n, p) prime_factors[p] = k return prime_factors
def main(N=10**8): c = 0 u = int(N**0.5) primes = primerange(1, u + 1) for n, p in enumerate(primes): c += primepi((N - 1) // p) - n return c
def main(N=5000): i = 11 while True: w = ways(i, primepi(i)) if w > N: return i else: i += 1
def primepi(n): """Number of primes less than a value http://mathworld.wolfram.com/PrimeCountingFunction.html This is here as a reminder of what is in sympy >>> primepi(10**5) 9592 """ return sympy.primepi(n)
def pi(n): n = np.floor(n).astype(int) if isinstance(n,(list,np.ndarray)): out = [] for cur_num in n: out.append(sp.primepi(cur_num)) return out else: out=0 for x in range(1,n): if sp.isprime(x): out+=1 return out
def method3_non_recursive(n): primes = primesieve.primes(n) SS = [[1]] S = [1] for k in range(1, n + 1): if k % 5_000 == 0: print(f"progress: {k}") SSk = [] pi = sympy.primepi(k) for i in range(pi): p = primes[i] SSkmp = SS[k - p] SSk.append(((SSk[i - 1] if i > 0 else 0) + p * (SSkmp[i] if i < len(SSkmp) else (SSkmp[-1] if SSkmp else 0))) % MODULUS) SS.append(SSk) S.append(SSk[pi - 1] if pi >= 1 else 0)
def method3(n): primes = primesieve.primes(n) # S[k, i] is the sum of numbers whose prime factor sum is k and # whose prime factors are among the primes[0], primes[1], ..., # primes[i]. @functools.lru_cache(maxsize=None) def S(k, i): if k == 0: return 1 if i < 0: return 0 p = primes[i] if k < p: return S(k, i - 1) else: return (S(k, i - 1) + p * S(k - p, i)) % MODULUS return [S(k, sympy.primepi(k) - 1) for k in range(n + 1)]
#!/usr/bin/python3 # -*- coding: utf-8 -*- # A composite is a number containing at least two prime factors. For example, 15 = 3 × 5; 9 = 3 × 3; 12 = 2 × 2 × 3. # There are ten composites below thirty containing precisely two, not necessarily distinct, prime factors: 4, 6, 9, 10, 14, 15, 21, 22, 25, 26. # How many composite integers, n < 10^8, have precisely two, not necessarily distinct, prime factors? # 10^8'den yarısından küçük her asal için kendinden küçük eşit asal sayılarla çarpımından oluşturulan sayılar sayıldığında aranan sonuç bulunmuş oluyor. from sympy import primepi from sympy import primerange sonuc = 0 LIMIT = 10**8 primes = primerange(2, LIMIT // 2) for n in primes: if (n < LIMIT**(0.5)): m = primepi(n) else: m = primepi(LIMIT // n) sonuc += m print(sonuc)
def pi(x): values = np.zeros(len(x)) for index, val in enumerate(x): pi = sp.primepi(val) values[index] = pi return values def division(x, func): return np.divide(func(x), f(x)) # SECCIÓN PRINCIPAL # ------------------------------------------------ x = int(sys.argv[1]) counter = 59 closure = True while closure and counter <= x: pi = sp.primepi(counter) closure = pi > g(counter) and pi < h(counter) counter += 1 if closure: print("La función pi(x) con x <= " + str(x) + " se encuentra acotada.") else: print("La función pi(x) con x <= " + str(x) + " no se encuentra acotada para el valor " + str(counter - 1))
import math import sympy x = 200 pi_x = sympy.primepi(x) print(pi_x)
# http://mathworld.wolfram.com/Semiprime.html from __future__ import division from sympy import prime, primepi n = 10 ** 8 s = 0 for k in range(1, primepi(sqrt(n)) + 1): s += primepi(n / prime(k)) - k + 1 print s
def pi(x): values = np.zeros(len(x)) for index, val in enumerate(x): pi = sp.primepi(val) values[index] = pi return values
def numSemiprimes(x): base = list(sieve.primerange(1, int(x**0.5) + 1)) return sum([ primepi(int(x / base[k - 1]) + 1) - k + 1 for k in range(1, primepi(int(x**0.5))) ])
from sympy import primerange, primepi import time start = time.time() n = 10**8 count = 0 for i in primerange(2, 10**4): count += primepi(n / i) - primepi(i) + 1 if time.time() - start > 10: print(i, count) start = time.time() print(count)
nextx = xcenter - width / children - dx / children for neighbor in neighbors: nextx += dx pos = hierarchy_pos(G, neighbor, width=dx, vert_gap=vert_gap, vert_loc=vert_loc - vert_gap, xcenter=nextx, pos=pos, parent=root) return pos K = 5 CHILDREN = 2**(primepi(K - 1)) M = 86 FONT_SIZE = 0 NODE_SIZE = 2 DPI = 300 ROOT = 0 list_ = [] chosen_numbers = [ 5, 7, 9, 10, 11, 13, 14, 16, 17, 20, 21, 22, 23, 25, 26, 27, 30, 32, 34, 35, 36, 37, 39, 40, 41, 42, 44, 47, 49, 51, 52, 54, 56, 57, 58, 59, 61, 63, 64, 65, 66, 68, 71, 73, 76, 77, 79, 81, 83, 84 ] for M in chosen_numbers: graph = general_collatz_tree(M, K, root=ROOT + 1)