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

前端 未结 12 1569
无人共我
无人共我 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 12:09

    • Find the first prime which divides the number N.
    • Let's say that prime is d.
    • Divide N by d.
    • This is the required result that you want.

提交回复
热议问题