def main(limit): primes = Primes(limit) def circular(p): d = digits(p) return all(primes.isPrime(num(d[i:] + d[:i])) for i in range(1, len(d))) return sum(map(circular, takewhile(lambda n: n < limit, primes.gen())))
def main(limit): primes = Primes(limit) def circular(p): d = digits(p) return all( primes.isPrime(num(d[i:] + d[:i])) for i in range(1, len(d))) return sum(map(circular, takewhile(lambda n: n < limit, primes.gen())))
def main(limit=28123): primes = Primes(limit) abundant = [n for n in range(limit + 1) if n < primes.sumDivisors(n)] abundantSet = set(abundant) def can(n): for a in abundant: if 2 * a > n: break if n - a in abundantSet: return True return False return sum(n for n in range(limit + 1) if not can(n))
def main(N, solns): primes = Primes(N) rv = 0 for n in range(N): count = 0 for A in primes.divisors(n): if A * A < 3 * n and (A + n // A) % 4 == 0: count += 1 if count > solns: break if count == solns: rv += 1 return rv
def main(limit): rv = 0 for p in Primes(limit).gen(): if p > limit: break if not isFactor(p): rv += p return rv
def solve(self,number): p = Primes.primes() next = p.next() largest = 0 max = math.sqrt(number) while next < max: if number % next == 0: largest = next next = p.next() return largest
from lib import Primes primes = Primes() def main(limit): mem = [False] * limit for pa in primes.gen(): sq = pa * pa if sq > limit: break for pb in primes.gen(): cu = pb * pb * pb if sq + cu > limit: break for pc in primes.gen(): fo = pc * pc * pc * pc tot = sq + cu + fo if tot > limit: break mem[tot] = True return sum(mem) if __name__ == '__main__': print(main(50000000)) # 1097343
def solve(self,number): p = Primes.primes() for i in range(0,number): p.next() return p.next()
from lib import Primes import heapq primeGen = Primes() def main(e, m): factors = list(map(primeGen.get, range(e))) heapq.heapify(factors) n = 1 for _ in range(e): factor = factors[0] n = n * factor % m heapq.heappushpop(factors, factor ** 2) return n if __name__ == '__main__': print(main(500500, 500500507)) # 35407281
from lib import numLen, Primes from collections import defaultdict prime = Primes() class chainLenObj(): def __init__(self, limit): self.limit = limit self.mem = [None] * limit self.mem[1] = 1 def get(self, n): if self.mem[n] == None: self.mem[n] = 1 + self.get(prime.phi(n)) return self.mem[n] def gen(self, length): for p in prime.gen(): if p >= self.limit: break print(p) if self.get(p) == length: yield p def main(limit, length): clo = chainLenObj(limit) return sum(clo.gen(length))
nw = [] for a in [1] + ws: while True: a *= n if a > limit // 2: break yield a nw.append(a) if not nw: return ws = nw def dpf(n): return set(p for p, _ in primes.factors(n)) primes = Primes() def main(limit): hits = set() for c in range(limit): f = list(primes.factors(c)) R = multiply(p**(n-1) for p, n in f) badf = set(p for p, _ in f) for a in aa((p for p in primes.gen() if p not in badf), c): b = c - a if a < b and rad(a)*rad(b) < R and dpf(b).isdisjoint(dpf(a) | badf): hits.add((a, b, c)) return sum(c for _, _, c in hits) if __name__ == '__main__': print(main(1000)) # 18407904
while True: a *= n if a > limit // 2: break yield a nw.append(a) if not nw: return ws = nw def dpf(n): return set(p for p, _ in primes.factors(n)) primes = Primes() def main(limit): hits = set() for c in range(limit): f = list(primes.factors(c)) R = multiply(p**(n - 1) for p, n in f) badf = set(p for p, _ in f) for a in aa((p for p in primes.gen() if p not in badf), c): b = c - a if a < b and rad(a) * rad(b) < R and dpf(b).isdisjoint( dpf(a) | badf): hits.add((a, b, c)) return sum(c for _, _, c in hits)