-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalg3.py
More file actions
34 lines (27 loc) · 696 Bytes
/
Copy pathalg3.py
File metadata and controls
34 lines (27 loc) · 696 Bytes
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
from typing import List
def nested_sum_of_polynomial(
a: int,
b: int,
k: int,
f_coefs: List[float],
) -> float:
def func(x: int) -> int:
# Horner's method for polynomial evaluation
acc = f_coefs[-1]
for coef in f_coefs[-2::-1]:
acc *= x
acc += coef
return acc
pascal = 1 # (k - 1 choose k - 1)
res = 0
for i in range(a, b + 1):
res += pascal * func(a + b - i)
pascal *= (k + i - a) / (i - a + 1)
return res
# result = nested_sum_of_polynomial(
# a=1,
# b=100,
# k=4,
# f_coefs=[5, -1, 1, -5, -3, 3], # Put your function coefficients here
# )
# print(int(result))