Пример #1
0
def below(M):
  m = int(sqrt(M - (2**3 + 2**4)))
  print "need primes less than %s" % m
  primes = list(prime_gen(max_size = m))

  nums = set([])
  for p1 in primes:
    if p1**2 + 2**3 + 2**4 > M:
      break
    for p2 in primes:
      if p1**2 + p2**3 + 2**4 > M:
        break
      for p3 in primes:
        if p1**2 + p2**3 + p3**4 > M:
          break
        nums.add(p1**2+p2**3+p3**4)
  return len(nums)
Пример #2
0
from math import sqrt
from helpers import cached_prime, prime_gen, factor

def totient(n, f):
  prod = 1
  for p in f:
    prod *= (1 - float(1) / p)
  return int(round(prod * n))

def is_perm(n1, n2):
  return sorted(str(n1)) == sorted(str(n2))

limit = 10**7
primes = list(prime_gen(max_size = limit/2 ))

m = limit
for p in reversed(primes):
  for p2 in primes:
    if p*p2 > limit:
      break
    t = totient(p*p2, (p, p2))
    if is_perm(p*p2, t):
      if m > float(p)*p2/t:
        m = float(p)*p2/t
        print(p*p2, t, float(p)*p2/t)

Пример #3
0
from helpers import factor, cached_prime, prime_gen
from math import sqrt

def totient(n):
  f = factor(n)
  prod = 1
  for p in f:
    prod *= (1 - float(1) / p)
  return int(round(prod * n))

limit = 1000000
cached_prime(1000000)
prod = 1
for p in prime_gen():
  prod *= p
  if prod <= limit:
    t = totient(prod)
    print (prod, t, float(prod) / t)
  else:
    break
Пример #4
0
    return (left, right)

def is_family(f):
  for i in range(len(f)):
    for j in range(i + 1, len(f)):
      left = int_concat(f[i], f[j])
      right = int_concat(f[j], f[i])
      if not (is_prime(left) and is_prime(right)):
        return False
  return True

sieve(100000000)
max_prime = 10000
fam_size = 3

primes = list(prime_gen(max_size = max_prime))
def fams():
  for i in range(1, len(primes)):
    for j in range(i+1, len(primes)):
      if not is_family((primes[i], primes[j])):
        continue
      print (primes[i], primes[j])
      for k in range(j+1, len(primes)):
        if not is_family((primes[i], primes[j], primes[k])):
          continue
        for l in range(k + 1, len(primes)):
          if not is_family((primes[i], primes[j], primes[k], primes[l])) or k > l:
            continue
          for m in range(l + 1, len(primes)):
            if not is_family((primes[i], primes[j], primes[k], primes[l], primes[m])):
              continue