ArbitPrec/abrivan
ArbitPrec/Stephan
t1from math import fabst1from math import fabs
2from decimal import Decimal2from decimal import Decimal
3from decimal import getcontext3from decimal import getcontext
44
55
6def f(x, eq):6def f(x, eq):
7    return Decimal(eval(eq))7    return Decimal(eval(eq))
88
99
10def root_finding(a, b, eps, eq):10def root_finding(a, b, eps, eq):
11    c = Decimal(0)11    c = Decimal(0)
12    c = Decimal((a+b)/2)12    c = Decimal((a+b)/2)
13    while fabs(f(Decimal(c), eq)) > eps:13    while fabs(f(Decimal(c), eq)) > eps:
14        if sgn(f(a, eq))*sgn(f(Decimal(c), eq)) < 0:14        if sgn(f(a, eq))*sgn(f(Decimal(c), eq)) < 0:
15            b = Decimal(c)15            b = Decimal(c)
16            c = Decimal((a+c)/2)16            c = Decimal((a+c)/2)
1717
18        else:18        else:
19            a = Decimal(c)19            a = Decimal(c)
20            c = Decimal((b+c)/2)20            c = Decimal((b+c)/2)
2121
22    return c22    return c
2323
2424
25def sgn(x):25def sgn(x):
26    if (x > 0):26    if (x > 0):
27        return 127        return 1
28    elif (x < 0):28    elif (x < 0):
29        return -129        return -1
30    else:30    else:
31        return 031        return 0
3232
3333
34eq = input()34eq = input()
35a = Decimal(-1.5)35a = Decimal(-1.5)
36b = Decimal(1.5)36b = Decimal(1.5)
37e = int(input())37e = int(input())
38if eq == "x":38if eq == "x":
39    str = "0."39    str = "0."
40    for i in range(e):40    for i in range(e):
41        str += "0"41        str += "0"
42    print(str)42    print(str)
43else:43else:
44    eps = Decimal(10**(-e))44    eps = Decimal(10**(-e))
45    getcontext().prec = e+2045    getcontext().prec = e+20
46    root = Decimal(root_finding(a, b, eps, eq))46    root = Decimal(root_finding(a, b, eps, eq))
47    print(round(root, e))47    print(round(root, e))
4848
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op