Possible optimization in my code?

前端 未结 3 813
孤城傲影
孤城傲影 2020-12-18 14:06

In order to solve the Euler Project problem n°5, I wrote the following program:

class p5
{
    const int maxNumber = 20;
    static void Main(string[] args)
         


        
3条回答
  •  伪装坚强ぢ
    2020-12-18 14:20

    Well, one thing is that you only have to test even numbers, so start at 0, and increase by 2. this is due to the fact that an even number will never evenly divide into an odd number. you could also start the search at a factorial of 10, so 10*9*8*7..and so on so other words start at 10! which is 3 628 800. that may help run it faster. also on average my speed in C was 10 seconds, so you're code is actually fine.

提交回复
热议问题