eolymp
Problems

Fibonacci

published at 1/11/20, 9:03:56 am

include<bits/stdc++.h>

using namespace std; int main() { long long n,a,b=1,c=0; cin>>n;

for(a=0;n>a;a++){

b=b+c; c=b-c;

}
cout<<b;

return 0; }

published at 2/17/22, 11:09:04 am

include <iostream>

using namespace std;

int main(){

int n,a=0,b=1,i; int c=a+b; cin>>n; for(i=0;i<n;i++){

c=a+b;
a=b;
b=c;

} cout<<c;

return 0; }

published at 3/10/22, 10:01:42 am

include <iostream>

using namespace std; int M[45]; int F(int n){ if (n<=1)return 1; if (M[n]) return M[n]; return M[n]=F(n-1)+F(n-2); } int main() { int n; cin>>n; cout<<F(n); }

published at 8/22/22, 9:00:04 pm

include<stdio.h>

using namespace std; int main(){ int n,i,a1=1,a2=1,f; scanf("%d",&n); for(i=1; i<n; i++){ f=a1+a2; a1=a2; a2=f; } printf("%d",f); }