#B2147. Nested Radical Function Evaluation

    ID: 11229 Type: Default 1000ms 256MiB

Nested Radical Function Evaluation

Nested Radical Function Evaluation

Given the function defined by the following nested radical expression:

\(f(x,n)=\sqrt{n+\sqrt{(n-1)+\sqrt{(n-2)+\sqrt{\cdots+2+\sqrt{1+x}}}}}\)

Your task is to compute the value of \(f(x,n)\).

Note: The computation starts from the innermost radical \(\sqrt{1+x}\), and then for each integer \(i=2,3,\dots,n\) you compute \(\sqrt{i+\text{previous value}}\).

inputFormat

The input consists of two numbers separated by a space:

  • x: a real number
  • n: a positive integer

These represent the value to be added in the innermost radical and the number of nested levels respectively.

outputFormat

Output the computed value of \(f(x,n)\) as a floating-point number with 6 decimal places of precision.

sample

0 1
1.000000