Created
February 8, 2016 11:59
-
-
Save raa0121/910d328bf74d3049a7c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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