Fractions are better when continued
InterviewTime limit1sMemory limit1024 MB
Given N, print the numerator of p_N, where p_0 = 1 and p_N = 1 / (1 + p_(N-1)), written in lowest terms.
- Level
Easy2 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Little Charles was one of the best competitive programmers in the world. However, he never really liked programming. Now that he is retired, he can dedicate his studies to what he really loves: continued fractions.
To prepare for the upcoming Imensa Competição de Phrações Contínuas (ICPC), he needs to solve the following problem:
Define as the level fraction. Then define as the level fraction, . Also, is the level fraction, , and so on.
Given an integer , help Charles determine the value of the numerator of the fraction .
Input
The first and only line contains an integer ().
Output
The value can be written as a fraction , where and are coprime. Print a line containing the value of .