Mọi người có thể giải thích cho mình số 50 trong thuật toán có nghĩa là gì không??
Và tại sao lại là 50. Trong tài liệu mình đọc nó chỉ ghi là “50” là một số ma thuật… kiểm soát khả năng test của số nguyên tố.
Đây là nguyên văn.
This program is a straightforward encoding of the prose description above: it starts with the primes, computes the corresponding Mersenne numbers, filters out all but the primes (the magic number 50 controls the probabilistic primality test), limits the resulting stream to twenty elements, and prints them out.
Đây là mã:
public class PrimaryNumber {
static Stream<BigInteger> primes() {
return Stream.iterate(BigInteger.TWO, BigInteger::nextProbablePrime);
}
public static void main(String[] args) {
primes().map(
p ->
BigInteger.TWO.pow(p.intValueExact()).subtract(BigInteger.ONE))
.filter(mersense -> mersense.isProbablePrime(50))
.limit(20)
.forEach(System.out::println);
}
}
Thank all!