Challenge: Climbing Stairs

Lab C++ Beginner 10 points

Climbing 1 or 2 steps at a time, print the number of ways to climb n steps.

Input

One whole number n (1 ≤ n ≤ 90).

Output

The number of ways.

Example

Input

2

Output

2
Sample input available Sample output available
Editor
C++

Hints

ways[i] = ways[i - 1] + ways[i - 2].

Use long long: the answer for 90 is about 4.6 × 10¹⁸.

Solution explanation

Fibonacci in disguise, solved bottom-up in O(n).

Show solution
#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    long long a = 1, b = 1;
    for (int i = 2; i <= n; i++) {
        long long c = a + b;
        a = b;
        b = c;
    }
    cout << b << endl;
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD