R = sqrt(98 + sqrt(95 + sqrt(92 + ... + sqrt(5 + sqrt(2)))))
2 ответа
Если вы далеки от программирования, то вот вам решение:
import math
def Calc(val):
if (val == 2): return math.sqrt(2)
res = math.sqrt(val + Calc(val - 3))
return res
print (Calc(98))
def recursive(n, step=1, debug=False):
if n <= step:
return n**.5
if debug:
print(f'{n}**.5 + recursive(n={n-step}, step={step}))**.5', )
return (n + recursive(n=n-step, step=step))**.5
from functools import reduce
def iterative(n, step=1):
return reduce(lambda x,y: (x**.5 + y), range(2, n+step, step))**.5
результат:
In [246]: recursive(98, 3)
Out[246]: 10.40440565283661
In [247]: iterative(98, 3)
Out[247]: 10.40440565283661