Project Euler #10 (Python)

前端 未结 9 1297
情深已故
情深已故 2021-01-22 07:27

Why is my algorithm for finding the sum of all prime numbers below 2 million so slow? I\'m a fairly beginner programmer and this is what I came up with for finding the solution:

9条回答
  •  北海茫月
    2021-01-22 08:01

    You need to use prime sieve check out eratostheneses sieve and try to implement it in code.

    Trial division is very inefficient for finding primes because it has complexity n square, the running time grows very fast. This task is meant to teach you how to find something better.

提交回复
热议问题