Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Numerics;
- using System.Diagnostics;
- namespace Euler57
- {
- class Program
- {
- static BigInteger numerator = 1;
- static BigInteger denominator = 1;
- static BigInteger tmpNumerator = 0;
- static StringBuilder stringCounter = new StringBuilder();
- static int digitLength = 0;
- static int totalFractions = 0;
- static Stopwatch mywatch = new Stopwatch();
- static void Main(string[] args)
- {
- mywatch.Start();
- for (int i = 0; i < 1000; i++)
- {
- tmpNumerator = (denominator * 2) + numerator;
- denominator = numerator + denominator;
- numerator = tmpNumerator;
- stringCounter.Append(numerator);
- digitLength = stringCounter.Length;
- stringCounter.Append(denominator);
- if (digitLength > (stringCounter.Length - digitLength))
- totalFractions++;
- stringCounter.Clear();
- }
- mywatch.Stop();
- Console.WriteLine("Took " + mywatch.ElapsedMilliseconds + "ms to complete it.");
- Console.WriteLine("Answer is "+totalFractions);
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement