daily pastebin goal
46%
SHARE
TWEET

Fibonacci Numbers

keverman Jan 18th, 2018 39 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int fib(int n, long long *F = F)
  2. {
  3.     if(n == 0) return 0;
  4.     if(n == 1 || n == 2) return (F[n] = 1);
  5.     if(F[n]) return F[n];
  6.  
  7.     int k = (n & 1) ? (n + 1) / 2 : n / 2;
  8.  
  9.     F[n] = (n & 1) ? (fib(k) * fib(k) + fib(k - 1) * fib(k - 1))
  10.            : (2 * fib(k - 1) + fib(k)) * fib(k);
  11.  
  12.     return F[n];
  13. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top