Project Euler #10 Java solution not working

后端 未结 6 444
春和景丽
春和景丽 2020-12-12 00:01

I\'m trying to find the sum of the prime numbers < 2,000,000. This is my solution in Java but I can\'t seem get the correct answer. Please give some input on what could b

6条回答
  •  萌比男神i
    2020-12-12 00:21

    You're treating as prime those numbers that are only divisible by their square root (like 25). Instead of i < Math.sqrt(nr) try i <= Math.sqrt(nr).

    That's a really inefficient way to find primes, incidentally.

提交回复
热议问题