コード例 #1
0
ファイル: 035.py プロジェクト: pavelb/project-euler-python
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())))
コード例 #2
0
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())))
コード例 #3
0
ファイル: 127_0.py プロジェクト: pavelb/project-euler-python
          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

c = 9
for a in aa((p for p in primes.gen() if p not in dpf(c)), c):
  print(a)
コード例 #4
0
        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

c = 9
for a in aa((p for p in primes.gen() if p not in dpf(c)), c):
    print(a)