optimal algorithm for finding unique divisors

前端 未结 1 441
不知归路
不知归路 2020-12-22 05:01

I was just thinking of a problem which does not seem to be much hard but when we think of doing it optimally, it becomes quite a good problem. The problem is- We have been g

相关标签:
1条回答
  • 2020-12-22 06:04

    One obvious optimization is the following - do sieve of eratosthenes to fatorize all numbers up to a value you know is higher then any single one in the list you are given. Now you can iterate over all the factors of a given number from that list.

    What you do next is: for each number from the list and each of its prime factors p you should divide N by p until it is divisible by it. After you do that the divisors you are looking for are all divisors of the remaining number.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题