Prime factor of 300 000 000 000?

前端 未结 19 750
无人及你
无人及你 2021-01-03 10:23

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

19条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-03 10:54

    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...

提交回复
热议问题