题解:简单的斐波那契数列
#include <cstdio> #include <iostream> using namespace std; long long f[51]; int main() { int i,n; f[1]=1; f[2]=2; for(int i=3; i<51; i++) f[i]=f[i-1]+f[i-2]; while(cin>>n) cout<<f[n]<<endl; return 0; }
2023-11-13 16:37:40
题解:简单的斐波那契数列
#include <cstdio> #include <iostream> using namespace std; long long f[51]; int main() { int i,n; f[1]=1; f[2]=2; for(int i=3; i<51; i++) f[i]=f[i-1]+f[i-2]; while(cin>>n) cout<<f[n]<<endl; return 0; }