I need an optimal algorithm to find the largest divisor of a number N. Preferably in C++ or C#

前端 未结 12 1590
无人共我
无人共我 2020-12-29 11:51

I am currently using the following code but its very slow for large numbers



        static int divisor(int number)
        {
            int i;
                    


        
12条回答
  •  难免孤独
    2020-12-29 11:59

    One of the industry standard methods for finding factors of large numbers is the Quadratic Sieve algorithm.

    Have a read of this:

    http://en.wikipedia.org/wiki/Quadratic_sieve

    P.S. you should also consider how big your numbers are. Different factorisation algorithms tend to perform well for a certain size, and not for others. As noted in the QS wiki article, this method is generally the fastest for numbers less than about 100 decimal digits.

提交回复
热议问题