Algorithm to find all primes from 2 to 1000 not working

后端 未结 4 674
悲哀的现实
悲哀的现实 2021-01-02 09:04

Here\'s a piece of code to compute all primes from 2 to 1000 using the statement, that a number n is a prime number iff:

In the first version I think that I

4条回答
  •  轮回少年
    2021-01-02 10:01

    Java doubles (i.e., the outputs of pow) do not represent large numbers precisely enough to yield a correct remainder. You should switch to modular exponentiation.

提交回复
热议问题