def main(args): if args.test: K = 20 N = 100 else: K = 1000 N = K*K primes = PrimeNumberPool(K) prime_cube_partnership = [] for k in range(1, K): p = 3*k*(k+1)+1 if primes.IsPrime(p): prime_cube_partnership.append(p) n = k*k*k m = k*k*(k+1) logger.debug("{}^3+{}^2x{} = {}^3".format(n, n, p, m)) if p > N: break logger.debug(prime_cube_partnership) answer = len(prime_cube_partnership) logger.info("answer: {}".format(answer))
def main(args): primes = PrimeNumberPool() if args.test: N = 5 for n in [7, 41]: logger.debug("A({}) = {}".format(n, A(n))) else: N = 25 composite = [] t = 1 while len(composite) < N: t += 1 for d in [1, 3, 7, 9]: n = t * 10 + d if primes.IsPrime(n): continue an = A(n) if (n - 1) % an == 0: composite.append(n) logger.debug("A({}) = {}".format(n, an)) logger.debug(composite) answer = sum(composite) logger.info("answer: {}".format(answer))
def main(args): if args.test: M = 50 else: M = 50*1000*1000 prime = PrimeNumberPool() prime.IsPrime(M) rslt = [] for p1 in prime.numbers: n1 = p1*p1 for p2 in prime.numbers: n2 = p2*p2*p2 if (n2 > M): break for p3 in prime.numbers: n3 = p3*p3*p3*p3 if (n3 > M): break n = n1+n2+n3 if (n < M): rslt.append((n, p1, p2, p3)) logging.debug(len(rslt)) ns = set([x[0] for x in rslt]) logging.info("answer: {}".format(len(ns)))
def main(args): prime = PrimeNumberPool() cprime = set() ts1 = time.time() m = 2000 for i in range(m): prime.NewPrime() pm = prime.numbers[:m] ts2 = time.time() logging.debug("time for build primes {}".format(ts2 - ts1)) for i in range(m): p1 = pm[i] for j in range(i, m): p2 = pm[j] if (not prime.IsPrime(CatNum(p1, p2))): continue if (not prime.IsPrime(CatNum(p2, p1))): continue cprime.add((p1, p2)) logging.debug(len(cprime)) ts3 = time.time() logging.debug("time for build prime pairs {}".format(ts3 - ts2)) for (p1, p2) in cprime: for p3 in pm: if (p3 <= p2): continue if (not Check(p3, [p1, p2], cprime)): continue for p4 in pm: if (p4 <= p3): continue if (not Check(p4, [p1, p2, p3], cprime)): continue for p5 in pm: if (p5 <= p4): continue if (not Check(p5, [p1, p2, p3, p4], cprime)): continue logging.info((p1, p2, p3, p4, p5)) logging.info("result: {}".format(sum([p1, p2, p3, p4, p5]))) return 0
def main(args): prime = PrimeNumberPool() n = 33 done = 0 while (done == 0): if (prime.IsPrime(n)): n += 2 continue if (Check(n, prime) == 0): logging.info(n) done = 1 else: n += 2
def main(args): primes = PrimeNumberPool() num_d = 5 num_p = 3 n = 3 while (float(num_p) / num_d > 0.1): n += 2 p = n * n - 3 * n + 3 for i in range(4): if (primes.IsPrime(p)): num_p += 1 p += n - 1 num_d += 4 logging.info(n)