fork download
  1. #include <iostream>
  2. #include <chrono>
  3. using namespace std;
  4.  
  5. uint64_t fib(const uint64_t n)
  6. {
  7. return n < 2 ? 1 : fib(n-1)*fib(n-2);
  8. }
  9.  
  10. int main()
  11. {
  12. uint64_t input;
  13.  
  14. cin >> input;
  15.  
  16. const auto start=chrono::high_resolution_clock::now();
  17.  
  18. const auto res=fib(input);
  19.  
  20. const double time=chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now()-start).count();
  21.  
  22. cout << "fib("<<input<<") = "<<res<<" computed in " << time/1000.0 << "ms.";
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0.8s 4504KB
stdin
42
stdout
fib(42) = 1 computed in 797.276ms.