chap2_4.cpp 637 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #include "utils.h"
  2. #include <limits>
  3. vector<u32>* fibon_seq(int size) {
  4. static vector<u32> elems;
  5. if (size <= 0 || size > 1024) {
  6. cout << "size is invalid!" << endl;
  7. return 0;
  8. }
  9. int current_size = elems.size();
  10. if (size > current_size) {
  11. for (int ix = current_size; ix < size; ++ix) {
  12. if (ix < 2) {
  13. elems.push_back(1);
  14. }
  15. else {
  16. int value_ix = elems[ix - 1] + elems[ix - 2];
  17. elems.push_back(value_ix);
  18. }
  19. }
  20. }
  21. return &elems;
  22. }
  23. int main() {
  24. vector<u32>* v = fibon_seq(100);
  25. if (v) {
  26. display(*v);
  27. }
  28. int max_int = numeric_limits<long>::max();
  29. cout << max_int << endl;
  30. return 0;
  31. }