-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13705.py
More file actions
69 lines (58 loc) · 1.42 KB
/
13705.py
File metadata and controls
69 lines (58 loc) · 1.42 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import math
from decimal import *
getcontext().prec = 50
getcontext().rounding = ROUND_HALF_UP
pi = Decimal('3.14159265358979323846264338327950288419716939937510')
a, b, c = input().split()
a = Decimal(a)
b = Decimal(b)
c = Decimal(c)
# print(a,b,c)
def decimal_sin(x):
x = x % (Decimal('2') * pi)
i = Decimal('1') # 1, 3, 5, 7 ...
lasts = Decimal('0')
value = Decimal(x)
fact = Decimal('1')
num = Decimal(x)
sign = Decimal(1)
while value != lasts:
lasts = value
i += 2
fact *= i * (i-1)
num *= x * x
sign *= -1
value += num / fact * sign
return Decimal(value)
def decimal_cos(x):
x = x % (Decimal('2') * pi)
i = Decimal('0') # 0, 2, 4, 8 ...
lasts = Decimal('0')
value = Decimal('1')
fact = Decimal('1')
num = Decimal(x)
sign = Decimal(1)
while value != lasts:
lasts = value
i += 2
fact *= i * (i-1)
num *= x * x
sign *= -1
value += num / fact * sign
return Decimal(value)
def func(x) -> float:
return a * x + b * decimal_sin(x) - c
def derivative(x) -> float:
return a + b * decimal_cos(x)
left = c / a - Decimal('1')
right = c / b + Decimal('1')
while right - left > Decimal(1e-20):
mid = (left + right) / 2
if func(mid) > 0:
right = mid
elif func(mid) < 0:
left = mid
else:
break
ans = (left + right) / 2
print(round(ans, 6))