#B2148. Recursive Continued Fraction Calculation
Recursive Continued Fraction Calculation
Recursive Continued Fraction Calculation
Given a mathematical function defined by the continued fraction:
$$ f(x,n)= \frac{x}{n+\frac{x}{(n-1)+\frac{x}{(n-2)+\cdots+\frac{x}{1+x}}}} $$
Implement a recursive function to compute f(x, n) for given values of x and a positive integer n. The recursion should stop when the denominator reaches the term 1+x
(i.e. when n reaches 0, return x). In other words, define the function recursively as:
Print the result rounded to six decimal places.
inputFormat
The input consists of a single line containing two numbers separated by spaces:
x
: a floating-point number.n
: a positive integer.
outputFormat
Output the computed value of f(x, n) rounded to six decimal places.
sample
5 1
0.833333