Project Euler #25: N-digit Fibonacci number

  • + 0 comments

    I used Binet's Formula. Only got 3/4 test case.

    public static void getFibs(int digit)
        {
            if(digit == 1) { Console.WriteLine(1); }
            else
            {
                double phi = 1.61803;
                double approx = Math.Pow(10,digit-1);
                double sqrtFive = Math.Sqrt(5);
                double ans = 0;
                int nth = 0;
                for(int i = 1; ans < approx; i++)
                {
                    ans = Math.Pow(phi,i) / sqrtFive;
                    nth = i;
                }
                Console.WriteLine(nth);
            }
            
        }