Skip to content

Instantly share code, notes, and snippets.

@terakun
Created March 20, 2014 17:06
Show Gist options
  • Save terakun/9668823 to your computer and use it in GitHub Desktop.
Save terakun/9668823 to your computer and use it in GitHub Desktop.
#include <iostream>
using ulong=unsigned long;
ulong fibo_sub(ulong,ulong,ulong);
ulong fibo(ulong n){
return (n==0)?0:fibo_sub(n,1,0);
}
ulong fibo_sub(ulong n,ulong a,ulong b){
return (n==1)?a:fibo_sub(n-1,a+b,a);
}
int main(){
ulong n;
std::cin>>n;
std::cout<<fibo(n)<<std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment