https://en.wikipedia.org/wiki/Brun%27s_theorem
http://numbers.computation.free.fr/Cons ... /twin.html
Как вычислить константу Бруна до 10^20 с помощью Python
зная, что проверка на простоту требует больших затрат и суммирование результата до 10^20 — это долгая задача?
Вот моя попытка за 2 цента:
Код: Выделить всё
IsPrimeКод: Выделить всё
digit_rootЕсли кто-то знает, что можно улучшить ниже, чтобы достичь вычисления до 10^20, пожалуйста.
Код: Выделить всё
import numpy as np
import math
import time
#Brun's constant
#p B_2(p)
#10^2 1.330990365719...
#10^4 1.616893557432...
#10^6 1.710776930804...
#10^8 1.758815621067...
#10^10 1.787478502719...
#10^12 1.806592419175...
#10^14 1.820244968130...
#10^15 1.825706013240...
#10^16 1.830484424658...
#B_2 should reach 1.9 at p ~ 10^530 which is far beyond any computational project
#B_2*(p)=B_2(p)+ 4C_2/log(p)
#p B2*(p)
#10^2 1.904399633290...
#10^4 1.903598191217...
#10^6 1.901913353327...
#10^8 1.902167937960...
#10^10 1.902160356233...
#10^12 1.902160630437...
#10^14 1.902160577783...
#10^15 1.902160582249...
#10^16 1.902160583104...
def digit_root(number):
return (number - 1) % 9 + 1
first25Primes=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
def IsPrime(n) :
# Corner cases
if (n 3):
if (not(((n-1) / 6) % 1 == 0 or ((n+1) / 6) % 1 == 0)):
return False
i = 5
while(i * i
Подробнее здесь: [url]https://stackoverflow.com/questions/78339449/what-is-the-best-approach-to-compute-bruns-constant-with-python-which-includes[/url]
Мобильная версия