eolymp
bolt
Try our new interface for solving problems
Problems

Fibonacci

published at 1/27/24, 9:09:34 pm

include <iostream>

using namespace std; long long fibonacci(int n) { if (n <= 1) return n; long long a = 0, b = 1, c; for (int i = 2; i <= n; ++i) { c = a + b; a = b; b = c; } return b; } int main() { int n; cin >> n; cout << fibonacci(n+1) << endl; return 0; }

published at 3/14/24, 6:14:56 pm

include <bits/stdc++.h>

define ll long long int

define ld long double

using namespace std; int main(){

ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n;
cin>>n;
ll x = 1, y = 1, k;
for(int i = 1; i<n; i++){
    k = y;
    y = x+y;
    x = k;
}
cout<<y;

} //TECHNOBLADE NEVER DIES