尔冬橙

博客园 首页 新随笔 联系 订阅 管理

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)
        {
            int a,b,c;
            for (c = 710; c >= 1; c--)
            {
                for (b = c-1; b >= 1; b--)
                {
                   a = 1000-c-b;
                   if (a>0 && a<b && c * c == a * a +b * b )
                   {
                       Console.WriteLine("result:{0}",a*b*c);
                       Console.ReadLine();
                   }
                }
            }
        }

结果:31875000

 

posted on 2012-05-15 20:58  尔冬橙  阅读(265)  评论(0编辑  收藏  举报