We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #65: Convergents of e

Project Euler #65: Convergents of e

Problem
Submissions
Leaderboard
Discussions

This problem is a programming version of Problem 65 from projecteuler.net

The square root of 2 can be written as an infinite continued fraction.

  The infinite continued fraction can be written, , indicates that 2 repeats ad infinitum. In a similar way, .

It turns out that the sequence of partial values of continued fractions for square roots provide the best rational approximations. Let us consider the convergents for .

Hence the sequence of the first ten convergents for are:

What is most surprising is that the important mathematical constant,

The first ten terms in the sequence of convergents for are:

The sum of digits in the numerator of the convergent is .

Find the sum of digits in the numerator of the convergent of the continued fraction for .

Input Format

Input contains an integer

Constraints

Output Format

Print the answer corresponding to the test case.

Sample Input

10

Sample Output

17

Author

shashank21j

Difficulty

Easy

Max Score

100

Submitted By

1786

Need Help?


View discussions
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits

Choose a translation


  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy