def search(s): for n in nt.primeList(1000000): n = str(n) for i in n: if rep(n.replace(str(i), "*"), int(i == n[0])) == s: return n.replace(str(i), "*") return 0
def randprime(bits, safeness = 0): rng = random.SystemRandom() i = 0 while len('{0:b}'.format(i)) != bits: i = rng.getrandbits(bits) i += 1 - (i % 2) pList = list(primeList(1000)) while True: if all(i % p not in ([0] + [(p-(2**n-1))//2**n for n in range(safeness + 1)]) for p in pList) and all(isPrime(2**n*i+2**n-1) for n in range(safeness + 1)): return i i += 2
def squarefree(n): d = 1 for p in numbertheory.primeList(int(math.sqrt(n))): d *= p ** 2 n *= p ** 2 - 1 return n/d
import numbertheory def n(p1, p2): size = len(str(p1)) k = ((p2-p1)*pow(10**size, p2 - 2, p2))%p2 return k*10**size+p1 primes = numbertheory.primeList(10**9) next(primes)#2 next(primes)#3 p1 = next(primes)#5 total = 0 for p2 in primes: total += n(p1, p2) p1 = p2 print(total)
import numbertheory LIMIT = 100000 l = [0]*LIMIT l[0] = 1 plist = numbertheory.primeList(LIMIT*2+1) next(plist) for x in plist: for y in range(int((LIMIT - x//2)**.5)): l[x//2+y**2] = 1 for x in range(LIMIT): if l[x] == 0: print(2*x+1) break
import numbertheory as asdf import math p = list(asdf.primeList(10**8)) s = 0 for prime in p: if prime * 2 < 10 ** 8: foo = list(asdf.primeList(10**8//prime)) for n in foo: if n >= prime: s += 1 print(s)
##684288 (809, 31, 2) (827, 7, 2) ##105418 (191, 41, 2) (317, 17, 2) ##148902 (3, 53, 2) (383, 13, 2) ##149014 (11, 53, 2) (353, 29, 2) ##159094 (101, 53, 2) (367, 29, 2) ##171094 (149, 53, 2) (383, 29, 2) ##211894 (251, 53, 2) (433, 29, 2) ##334654 (431, 53, 2) (557, 29, 2) ##1142902 (997, 53, 2) (1069, 5, 2) ##1520134 (1171, 53, 2) (1223, 29, 2) ##2770054 (1619, 53, 2) (1657, 29, 2) ##12044494 (3449, 53, 2) (3467, 29, 2) ##334276 (359, 59, 2) (577, 11, 2) ##1068436 (929, 59, 2) (1033, 11, 2) ##2112556 (1381, 59, 2) (1453, 11, 2) ##12685048 (3511, 71, 2) (3547, 47, 2) t, r = 0, 0 trim = {} for q in nt.primeList(84): for c in nt.primeList(int(pow(5*10**7 - q**4, 1/3))): for s in nt.primeList(int(pow(5*10**7 - q**4 - c**3, 1/2))): x = s**2+c**3+q**4 if x in trim: #print(x, (s, c, q), *trim[x]) r += 1 else: t += 1 trim[x] = {(s, c, q)} print(t)
from numbertheory import primeList import numbertheory def residues(n, m): for i in range(m): yield pow(i, n, m) n = 13 for m in primeList(1000): t = numbertheory.totient(m) r = list(residues(n, m)) r = list(set(r)) r.sort() if m % n == 1 and numbertheory.isPrime(m): print(m , len(r), r)
import math import numbertheory #accounts for 2 and 5 count = 2 primes = list(numbertheory.primeList(1000000)) for prime in primes: cyclic = True prime = str(prime) if '0' not in prime and '2' not in prime and '4' not in prime and '5' not in prime and '6' not in prime and '8' not in prime: for x in range(1,len(prime)): cyclic = cyclic and numbertheory.isPrime(int(prime[x:]+prime[:x])) if cyclic: count += 1 print(prime) else: pass print(count)
import numbertheory import itertools plist = [x for x in numbertheory.primeList(10000)] for x in plist: i = list(map(int, [''.join(a) for a in itertools.permutations(str(x))])) for y in plist: if x < y and y != x and y in i and y in plist and (2 * y - x) in i and (2 * y - x) in plist: print(x, y, (2 * y - x))
import numbertheory LIMIT = 1000 c = [0]*(LIMIT + 1) p = numbertheory.primeList(LIMIT) for x in p: for k in range(LIMIT//x + 1): c[x*k] += x b = [0]*(LIMIT + 1) for n in range(1, LIMIT + 1): b[n] = (c[n] + sum(c[k] * b[n - k] for k in range(1, n)))//n for x in range(1, LIMIT): if b[x] > 5000: print(x, b[x]) break