FIBONACCI
View as PDF
Submit solution
Points:
0.10
Time limit:
1.5s
Memory limit:
64M
Input:
stdin
Output:
stdout
Authors:
Problem type
Mô tả vấn đề
Viết chương trình tìm số hạng thứ n-1 của dãy số Fibonacci với n>0
Input
Một số nguyên n (n ≤ 10~^5~)
Output
In ra số Fibonacci thứ n-1
Sample Input 1
2
Sample Output 1
1
Comments
include <bits/stdc++.h>
using namespace std;
int main() { int n; cin >> n; long long x,y; long long fibonacy; x=0; y=1; if(n>=2) { for (int i=2;i<=n;i++){ fibonacy = x + y; x = y; y = fibonacy; } cout << x; } else { if (n==0) cout << 0; else { if (n==1) cout << 1; } }
}