fibonacci.cpp 604 B

123456789101112131415161718192021222324252627282930
  1. #include <iostream>
  2. #include "gmp.h"
  3. using namespace std;
  4. int main() {
  5. mpz_t oldNumber;
  6. mpz_t currentNumber;
  7. mpz_t nextNumber;
  8. mpz_init (oldNumber);
  9. mpz_init (currentNumber);
  10. mpz_init (nextNumber);
  11. mpz_set_si (oldNumber, 1);
  12. mpz_set_si (currentNumber, 1);
  13. signed long int current;
  14. signed long int next;
  15. while (currentNumber > 0) {
  16. cout << currentNumber << endl;
  17. mpz_add (nextNumber, currentNumber, oldNumber);
  18. current = (long)currentNumber;
  19. next = (long)nextNumber;
  20. mpz_set_si (oldNumber, current);
  21. mpz_set_si (currentNumber, next);
  22. }
  23. return 0;
  24. }