Nth Fibonacci number and the sum so far
With F(1) = F(2) = 1 and F(n) = F(n − 1) + F(n − 2), print F(N) and the sum F(1) + F(2) + … + F(N), separated by a space.
Reported in: TCS NQT (29 Apr and 14 May 2024) (memory-based)
Input
One line: N.
Output
F(N) and the sum of the first N terms.
Constraints
1 ≤ N ≤ 90.
Example 1
Input:
7
Output:
13 33Example 2
Input:
10
Output:
55 143Example 3
Input:
1
Output:
1 1Hint: Walk through the series with two variables, adding each term to a running total.