尔冬橙

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

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

每个合数都可以写成几个质数相乘的形式。其中每个质数都是这个合数的因数,叫做这个合数的分解质因数。 分解质因数只针对合数。

c#代码:

class Program
    {
        static void Main(string[] args)
        {
            Int64 num = 600851475143;
            int prm = 2;
            while (prm < num)
            {
                if (num % prm == 0)
                    num /= prm;
                else prm += 1;
            }
            Console.WriteLine(prm);
        }
    }

如果有TC怎么办呢?

 

posted on 2012-05-12 00:09  尔冬橙  阅读(268)  评论(0编辑  收藏  举报