Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2. using System.Text;
  3. using System.Numerics;
  4. using System.Diagnostics;
  5.  
  6. namespace Euler57
  7. {
  8.     class Program
  9.     {
  10.         static BigInteger numerator = 1;
  11.         static BigInteger denominator = 1;
  12.         static BigInteger tmpNumerator = 0;
  13.         static StringBuilder stringCounter = new StringBuilder();
  14.         static int digitLength = 0;
  15.         static int totalFractions = 0;
  16.         static Stopwatch mywatch = new Stopwatch();
  17.  
  18.         static void Main(string[] args)
  19.         {
  20.             mywatch.Start();
  21.             for (int i = 0; i < 1000; i++)
  22.             {
  23.                 tmpNumerator = (denominator * 2) + numerator;
  24.                 denominator = numerator + denominator;
  25.                 numerator = tmpNumerator;
  26.  
  27.                 stringCounter.Append(numerator);
  28.                 digitLength = stringCounter.Length;
  29.                 stringCounter.Append(denominator);
  30.  
  31.                 if (digitLength > (stringCounter.Length - digitLength))
  32.                     totalFractions++;
  33.  
  34.                 stringCounter.Clear();
  35.  
  36.             }
  37.             mywatch.Stop();
  38.  
  39.             Console.WriteLine("Took " + mywatch.ElapsedMilliseconds + "ms to complete it.");
  40.             Console.WriteLine("Answer is "+totalFractions);
  41.  
  42.             Console.ReadLine();
  43.         }
  44.     }
  45. }