【ProjectEuler】ProjectEuler_009

// A Pythagorean triplet is a set of three natural numbers, a  b  c, for which,
// 
// a2 + b2 = c2
// For example, 32 + 42 = 9 + 16 = 25 = 52.
// 
// There exists exactly one Pythagorean triplet for which a + b + c = 1000.
// Find the product abc.

using System;
using System.Collections.Generic;
using System.Text;

namespace projecteuler009
{
    class Program
    {
        static void Main(string[] args)
        {
            F1();
        }

        private static void F1()
        {
            Console.WriteLine(new System.Diagnostics.StackTrace().GetFrame(0).GetMethod());
            DateTime timeStart = DateTime.Now;

            for (int a = 1; a < 997; a++)
            {
                for (int b = a; b < 997; b++)
                {
                    int c = 1000 - a - b;
                    if (a * a + b * b == c * c)
                    {
                        Console.WriteLine(a + "^2 * " + b + "^2 = " + c + "^2 = " + c * c);
                        Console.WriteLine("a*b*c = " + a * b * c);
                        Console.WriteLine("Total Milliseconds is " + DateTime.Now.Subtract(timeStart).TotalMilliseconds + "\n\n");
                        return;
                    }
                }
            }
        }
    }
}

/*
Void F1()
200^2 * 375^2 = 425^2 = 180625
a*b*c = 31875000
Total Milliseconds is 9.5012

By GodMoon
*/

你可能感兴趣的:(【ProjectEuler】ProjectEuler_009)