for loop finding the prime numbers

后端 未结 5 2062
生来不讨喜
生来不讨喜 2020-12-20 03:05

I am trying to run this code to print the sum of all the prime numbers less than 2 million. This loop is never ending. Can anyone tell me what is wrong with the code? It see

5条回答
  •  隐瞒了意图╮
    2020-12-20 03:54

    A naive isPrime function must calculate all the primes up to i (or at least up to sqrt(i)) each time it runs. Make sure your isPrime function caches its results!

提交回复
热议问题