diff options
author | Gennadiy Civil <gennadiycivil@users.noreply.github.com> | 2018-01-03 18:04:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-03 18:04:37 (GMT) |
commit | a3da63d97ace56fa28a0a54e192f28b10e2e0bb0 (patch) | |
tree | 79463195c16dc1699d01134bd99fb5674ae9f534 | |
parent | 90244a6aef73d28b7d300c5b3e9d7c94bd6f437a (diff) | |
parent | 1414d71af0c0f5a37df8d02972d304828bb6800e (diff) | |
download | googletest-a3da63d97ace56fa28a0a54e192f28b10e2e0bb0.zip googletest-a3da63d97ace56fa28a0a54e192f28b10e2e0bb0.tar.gz googletest-a3da63d97ace56fa28a0a54e192f28b10e2e0bb0.tar.bz2 |
Merge branch 'master' into tuple-msvcrefs/pull/1374/head
-rw-r--r-- | googletest/samples/prime_tables.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/googletest/samples/prime_tables.h b/googletest/samples/prime_tables.h index 92ce16a..55a3b44 100644 --- a/googletest/samples/prime_tables.h +++ b/googletest/samples/prime_tables.h @@ -103,11 +103,15 @@ class PreCalculatedPrimeTable : public PrimeTable { ::std::fill(is_prime_, is_prime_ + is_prime_size_, true); is_prime_[0] = is_prime_[1] = false; - for (int i = 2; i <= max; i++) { + // Checks every candidate for prime number (we know that 2 is the only even + // prime). + for (int i = 2; i*i <= max; i += i%2+1) { if (!is_prime_[i]) continue; // Marks all multiples of i (except i itself) as non-prime. - for (int j = 2*i; j <= max; j += i) { + // We are starting here from i-th multiplier, because all smaller + // complex numbers were already marked. + for (int j = i*i; j <= max; j += i) { is_prime_[j] = false; } } |