300 000 000 000主要因素? [英] Prime factor of 300 000 000 000?

查看:125
本文介绍了300 000 000 000主要因素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要找出超过300十亿的主要因素。我有也加入到他们的列表...很慢功能!它已经运行了大约一个小时,现在,我认为它有一个公平的距离走动。我做这完全地错误的或者是这正常吗?

编辑:林努力寻找数的最大素因子600851475143.

编辑: 结果:

  {
    名单< Int64的> ListOfPrimeFactors =新的名单,其中,Int64的>();
    Int64的号码= 600851475143;
    Int64的DividingNumber = 2;

    而(DividingNumber<数/ DividingNumber)
    {
        如果(编号%DividingNumber == 0)
        {
            ListOfPrimeFactors.Add(DividingNumber);
            数=数/ DividingNumber;
        }
        其他
            DividingNumber ++;
        }
        ListOfPrimeFactors.Add(数量);
        listBox1.DataSource = ListOfPrimeFactors;
    }
}
 

解决方案

您记住划​​分,你每个因素的因式分解号码作为你找到他们?

说,例如,你会发现2是一个因素。您可以添加到您的因素清单,但你把你试图通过该值factorise的数量。

现在你只是寻找150十亿的因素。你周围的每一次应该从你刚发现的因素开始。因此,如果2是一个因素,测试2了。如果你发现下一个因素是3,有2没有意义的测试了。

等等...

I need to find out the prime factors of over 300 billion. I have a function that is adding to the list of them...very slowly! It has been running for about an hour now and i think its got a fair distance to go still. Am i doing it completly wrong or is this expected?

Edit: Im trying to find the largest prime factor of the number 600851475143.

Edit: Result:

{
    List<Int64> ListOfPrimeFactors = new List<Int64>();
    Int64 Number = 600851475143;
    Int64 DividingNumber = 2;

    while (DividingNumber < Number / DividingNumber)
    {
        if (Number % DividingNumber == 0)
        {
            ListOfPrimeFactors.Add(DividingNumber);
            Number = Number/DividingNumber;
        }
        else
            DividingNumber++;
        }
        ListOfPrimeFactors.Add(Number);
        listBox1.DataSource = ListOfPrimeFactors;
    }
}

解决方案

Are you remembering to divide the number that you're factorizing by each factor as you find them?

Say, for example, you find that 2 is a factor. You can add that to your list of factors, but then you divide the number that you're trying to factorise by that value.

Now you're only searching for the factors of 150 billion. Each time around you should start from the factor you just found. So if 2 was a factor, test 2 again. If the next factor you find is 3, there's no point testing from 2 again.

And so on...

这篇关于300 000 000 000主要因素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆