t | from decimal import * | t | from decimal import * |
| inp = input() | | inp = input() |
| accuracy = int(input()) | | accuracy = int(input()) |
| getcontext().prec = accuracy + 2 | | getcontext().prec = accuracy + 2 |
| (left, right) = (Decimal(-1.5), Decimal(1.5)) | | (left, right) = (Decimal(-1.5), Decimal(1.5)) |
| x = Decimal((Decimal(right) + Decimal(left)) / 2) | | x = Decimal((Decimal(right) + Decimal(left)) / 2) |
| res = eval(inp) | | res = eval(inp) |
| while res != Decimal(0) and x != left and (x != right): | | while res != Decimal(0) and x != left and (x != right): |
| if res > Decimal(0): | | if res > Decimal(0): |
| right = Decimal(x) | | right = Decimal(x) |
| else: | | else: |
| left = Decimal(x) | | left = Decimal(x) |
| x = Decimal((Decimal(right) + Decimal(left)) / 2) | | x = Decimal((Decimal(right) + Decimal(left)) / 2) |
| res = eval(inp) | | res = eval(inp) |
| format_out = '{:.' + f'{accuracy}f' + '}' | | format_out = '{:.' + f'{accuracy}f' + '}' |
| print(format_out.format(x)) | | print(format_out.format(x)) |