From ff6e7f05a28842a0637818ce37528fbf6a072f0a Mon Sep 17 00:00:00 2001 From: bernd Date: Fri, 17 Mar 2017 15:21:08 +0100 Subject: [PATCH] version in python von thomas und bernd --- 2017-03-14/bernd_euler_87.py | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 2017-03-14/bernd_euler_87.py diff --git a/2017-03-14/bernd_euler_87.py b/2017-03-14/bernd_euler_87.py new file mode 100755 index 0000000..7d3f092 --- /dev/null +++ b/2017-03-14/bernd_euler_87.py @@ -0,0 +1,43 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +from math import sqrt + + +primzahlen = [2] +stop = 50000000 +menge = set() + + +# maximalwerte der einzelnen werte festlegen + +max_eins = int(stop ** (1/2.)) +max_zwei = int(stop ** (1/3.)) +max_drei = int(stop ** (1/4.)) +print "Maximalwerte:", max_eins, max_zwei, max_drei + + +# die primzahlen in der liste bis zu maximalwert ergänzen + +for x in xrange(3, max_eins, 2): + ende = sqrt(x) + for i in (p for p in primzahlen[1:] if p <= ende): + if x % i == 0: + break + else: + primzahlen.append(x) + + +for drei in primzahlen: + if drei > max_drei: + break + summand_drei = drei ** 4 + for zwei in primzahlen: + summand_zwei = zwei ** 3 + if summand_drei + summand_zwei >= stop: + break + for eins in primzahlen: + summe = summand_drei + summand_zwei + eins * eins + if summe <= stop: + menge.add(summe) +print "Count:", len(menge)