Advertisement
jtentor

Primer término Fibonacci con 1000 o más cifras (C#)

Sep 17th, 2014
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.Numerics;
  4.  
  5. namespace Desafio
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Stopwatch myTimer = Stopwatch.StartNew();
  12.  
  13.             BigInteger fib1 = BigInteger.One;
  14.             BigInteger fib2 = BigInteger.One;
  15.             BigInteger fib3 = fib1 + fib2;
  16.             int count = 3;
  17.             BigInteger maxNumber = BigInteger.Pow((BigInteger)10, 999);
  18.             while (fib3 < maxNumber)
  19.             {
  20.                 fib1 = fib2;
  21.                 fib2 = fib3;
  22.                 fib3 = fib1 + fib2;
  23.                 ++count;
  24.             }
  25.             myTimer.Stop();
  26.  
  27.             Console.WriteLine("{0}", count);
  28.             Console.WriteLine("{0}", fib3);
  29.  
  30.             Console.WriteLine("{0} nanosegundos", (double)myTimer.ElapsedTicks / 10);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement