oriolmarti97

Successió de Fibonacci en temps logarítmic

May 23rd, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.33 KB | None | 0 0
  1. double exp_rap(double a, int n) {
  2.     if (n==0) return 1;
  3.     int aux=exp_rap(a,n/2);
  4.     if (n%2==0) return aux*aux;
  5.     return aux*aux*a;    
  6. }
  7.  
  8. int fib_log(int n) {
  9.     const static double SQRT_5=sqrt(5);
  10.     const static double FI=(1+SQRT_5)/2;
  11.     const static double UMENYSFI=1-FI;
  12.     return ceil(exp_rap(FI,n)-exp_rap(UMENYSFI,n))/SQRT_5;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment