Skip to content

Instantly share code, notes, and snippets.

@raa0121
Created February 8, 2016 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raa0121/910d328bf74d3049a7c9 to your computer and use it in GitHub Desktop.
Save raa0121/910d328bf74d3049a7c9 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <gmpxx.h>
enum { BASE = 10 };
mpz_class fib(mpz_class n) {
if (0 == n) {
return 0;
} else if(1 == n){
return 1;
} else {
return fib(n-2) + fib(n-1);
}
}
int main() {
mpz_class a;
std::string buf;
std::cout << "fib(n) >> ";
while (std::cin >> buf) {
for (int i = 0; i <= std::stoi(buf) ; i++) {
std::cout << fib(static_cast<mpz_class>(i)).get_str();
std::cout << " ";
}
std::cout << std::endl;
std::cout << "fib(n) >> ";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment