profil:klasse9:abschnitt-9-1-1-loe1-2
Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
profil:klasse9:abschnitt-9-1-1-loe1-2 [2021/09/10 07:23] – angelegt lutz | profil:klasse9:abschnitt-9-1-1-loe1-2 [2021/09/10 08:45] (aktuell) – lutz | ||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
====Lösung der Aufgaben 1 und 2==== | ====Lösung der Aufgaben 1 und 2==== | ||
+ | |||
+ | **Aufgabe 1** | ||
+ | |||
+ | a) falsche Aussage\\ | ||
+ | b) keine Aussage\\ | ||
+ | c) keine Aussage\\ | ||
+ | d) keine Aussage\\ | ||
+ | e) wahre Aussage\\ | ||
+ | f) keine Aussage (Goldbachsche Vermutung) | ||
+ | |||
+ | **Aufgabe 2** | ||
+ | |||
+ | <code python goldbach.py> | ||
+ | def istPrimzahl(n): | ||
+ | prim = True | ||
+ | k = 2 | ||
+ | while k*k <= n and prim == True: | ||
+ | if n%k == 0: | ||
+ | prim = False | ||
+ | break | ||
+ | k +=1 | ||
+ | return prim | ||
+ | |||
+ | t = " | ||
+ | while t == " | ||
+ | n = int(input(" | ||
+ | while not(n > 2 and n%2 == 0): | ||
+ | n = int(input(" | ||
+ | |||
+ | a = 2 | ||
+ | b = n-2 | ||
+ | while a <= n//2: | ||
+ | if istPrimzahl(a): | ||
+ | if istPrimzahl(b): | ||
+ | break | ||
+ | a += 1 | ||
+ | b -= 1 | ||
+ | print(a," | ||
+ | t = input(" | ||
+ | |||
+ | </ | ||
+ | |||
+ | <code python goldbach_miller_rabin.py> | ||
+ | import random | ||
+ | |||
+ | def istPrimzahl(n, | ||
+ | |||
+ | # Implementation uses the Miller-Rabin Primality Test | ||
+ | # The optimal number of rounds for this test is 40 | ||
+ | # See http:// | ||
+ | # for justification | ||
+ | |||
+ | # If number is even, it's a composite number | ||
+ | |||
+ | if n < 0: | ||
+ | return False | ||
+ | |||
+ | if n == 1: | ||
+ | return False | ||
+ | |||
+ | if n == 2 or n == 3: | ||
+ | return True | ||
+ | |||
+ | if n % 2 == 0: | ||
+ | return False | ||
+ | |||
+ | r, s = 0, n - 1 | ||
+ | while s % 2 == 0: | ||
+ | r += 1 | ||
+ | s //= 2 | ||
+ | for _ in range(k): | ||
+ | a = random.randrange(2, | ||
+ | x = pow(a, s, n) | ||
+ | if x == 1 or x == n - 1: | ||
+ | continue | ||
+ | for _ in range(r - 1): | ||
+ | x = pow(x, 2, n) | ||
+ | if x == n - 1: | ||
+ | break | ||
+ | else: | ||
+ | return False | ||
+ | return True | ||
+ | |||
+ | |||
+ | t = " | ||
+ | while t == " | ||
+ | n = int(input(" | ||
+ | while not(n > 2 and n%2 == 0): | ||
+ | n = int(input(" | ||
+ | |||
+ | a = 2 | ||
+ | b = n-2 | ||
+ | while a <= n//2: | ||
+ | if istPrimzahl(a, | ||
+ | if istPrimzahl(b, | ||
+ | break | ||
+ | a += 1 | ||
+ | b -= 1 | ||
+ | print(a," | ||
+ | t = input(" | ||
+ | |||
+ | </ |
profil/klasse9/abschnitt-9-1-1-loe1-2.1631251389.txt.gz · Zuletzt geändert: 2021/09/10 07:23 von lutz