Beta

Square Root of 2

Description:

The method of periodic continued fractions is one of the many ways to calculate the square root of a natural number. This method uses as denominator a repetition for fractions. This repetition can be done by a fixed number of times.

For example, by repeating 2 times the continued fraction to calculate the square root of 2, we have the following equation.

21+12+12\sqrt{2} \approx1 + \dfrac{1}{2+\frac{1}{2}}

Input

The input is a natural number n (0 ≤ n ≤ 1000) that indicates the quantity of denominator repetitions in the continued fraction.

Output

The output is the approximate value of the square root with 10 decimal places.

Examples

calculate(0) => 1.0000000000
calculate(1) => 1.5000000000
calculate(5) => 1.4142857143

Notes

https://en.wikipedia.org/wiki/Periodic_continued_fraction

Fundamentals
Algorithms
Mathematics

Stats:

CreatedJan 31, 2017
PublishedJan 31, 2017
Warriors Trained170
Total Skips36
Total Code Submissions93
Total Times Completed31
Java Completions31
Total Stars3
% of votes with a positive feedback rating82% of 22
Total "Very Satisfied" Votes14
Total "Somewhat Satisfied" Votes8
Total "Not Satisfied" Votes0
Total Rank Assessments19
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • diegourban Avatar
  • user9644768 Avatar
Ad