#include <cstdio> #include <iostream> using namespace std; #ifdef ONLINE_JUDGE #define FINPUT(file) 0 #define FOUTPUT(file) 0 #else #define FINPUT(file) freopen(file,"r",stdin) #define FOUTPUT(file) freopen(file,"w",stdout) #endif int main() { FINPUT("in.txt"); FOUTPUT("out.txt"); int n; while(cin>>n && n) { long long int f1 = 1; long long int f2 = 2; long long int f3 = 3; int i = 4; while(i<=n) { f1 = f2; f2 = f3; f3 = f1+f2; i++; } if(n==1) cout<<f1<<endl; else if(n==2) cout<<f2<<endl; else if(n>=3) cout<<f3<<endl; } return 0; }
原文地址:http://blog.csdn.net/daringpig/article/details/25552527