1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| from math import *
from decimal import *
getcontext().prec=14
i=Decimal(14)
y=14
jesus=Decimal(log(pi))*Decimal(1)
P=Decimal(5)
n=Decimal(0.01)
precision=Decimal(100)
while P<10000000000000000001:
jesus=Decimal(log(pi))*Decimal(1)
Q=P//(Decimal(log(pi))*Decimal(1)+10**(-i-1))
while Q<=P:
if (P/Q)<(Decimal(log(pi))*Decimal(1)+10**(-i+1)):
Q=P
elif abs(precision)>abs((P/Q)-jesus):
precision = (P/Q)-jesus
a=P
b=Q
print("a=", a, "b=", b, "precision=", precision)
Q+=1
if P==Decimal(10000000000000000000)*n:
print (100*n, "%")
n+=1
if precision<Decimal(10)**(-y-1):
y+=1
i+=Decimal(1)
getcontext().prec=y
P+=1 |
Partager