How can I improve this code for Project Euler 7?

后端 未结 4 704
悲哀的现实
悲哀的现实 2021-01-27 02:29

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?

My solution:



        
4条回答
  •  轮回少年
    2021-01-27 03:19

    A number p is prime if it only divides by itself and 1. You are checking only for divison by 2, 3 and 5. This is not enough. Check for every number till p / 2, or better till sqrt(p).

提交回复
热议问题