Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.44 KB | None | 0 0
  1.     private static long[] GetTwoLastFibonacciSequenceElements(int n)
  2.         {
  3.             if (n <= 3)
  4.             {
  5.                 return new long[] {1, 1};
  6.             }
  7.             else
  8.             {
  9.                 var last = GetTwoLastFibonacciSequenceElements(n - 1);
  10.                 return new long[] {last[1], last[0] + last[1]};
  11.             }
  12.         }
  13.  
  14.         public static long GetFibonacciSequenceElement(int n)
  15.         {
  16.             var last = GetTwoLastFibonacciSequenceElements(n);
  17.             return last[0] + last[1];
  18.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement