Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Goldbachs-comet/Python/goldbachs-comet.py
Normal file
25
Task/Goldbachs-comet/Python/goldbachs-comet.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from matplotlib.pyplot import scatter, show
|
||||
from sympy import isprime
|
||||
|
||||
def g(n):
|
||||
assert n > 2 and n % 2 == 0, 'n in goldbach function g(n) must be even'
|
||||
count = 0
|
||||
for i in range(1, n//2 + 1):
|
||||
if isprime(i) and isprime(n - i):
|
||||
count += 1
|
||||
return count
|
||||
|
||||
print('The first 100 G numbers are:')
|
||||
|
||||
col = 1
|
||||
for n in range(4, 204, 2):
|
||||
print(str(g(n)).ljust(4), end = '\n' if (col % 10 == 0) else '')
|
||||
col += 1
|
||||
|
||||
print('\nThe value of G(1000000) is', g(1_000_000))
|
||||
|
||||
x = range(4, 4002, 2)
|
||||
y = [g(i) for i in x]
|
||||
colors = [["red", "blue", "green"][(i // 2) % 3] for i in x]
|
||||
scatter([i // 2 for i in x], y, marker='.', color = colors)
|
||||
show()
|
||||
Loading…
Add table
Add a link
Reference in a new issue