天天看點

【Project Euler】8 第八題



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.

static void main(string[] args)

        {

            for (int i = 1; i < 1000; i++)

            {

                for (int j = 1; j < 1000; j++)

                {

                    for (int k = 1; k < 1000; k++)

                    {

                        if (i + j + k == 1000)

                        {

                            if (j * j + k * k == i * i)

                            {

                                int x = i * j * k;

                                console.writeline(x);

                            }

                        }

                    }

                }

            }

        }

繼續閱讀