Run ID | Author | Problem | Lang | Verdict | Time | Memory | Code Length | Submit Time |
---|---|---|---|---|---|---|---|---|
34303 | 闻航 | 菲波那契数 | C++ | Accepted | 0 MS | 240 KB | 306 | 2023-12-17 19:23:39 |
#include<iostream> using namespace std; int main() { int n1=1,n2=1,n3,k,i; //k=第几个数 cin>>k; //1,1,2,3,5,8,13,21,34 if(k<=2){ cout<<'1'; }else{ i=3; while(i<=k){ n3=n1+n2; n1=n2; n2=n3; i++; } cout<<n3<<endl; } return 0; }