36 #ifndef GTEST_SAMPLES_PRIME_TABLES_H_ 37 #define GTEST_SAMPLES_PRIME_TABLES_H_ 47 virtual bool IsPrime(
int n)
const = 0;
58 if (n <= 1)
return false;
60 for (
int i = 2;
i*
i <=
n; i++) {
62 if ((n % i) == 0)
return false;
69 for (
int n = p + 1;
n > 0;
n++) {
83 : is_prime_size_(max + 1), is_prime_(new bool[max + 1]) {
84 CalculatePrimesUpTo(max);
89 return 0 <= n && n < is_prime_size_ && is_prime_[
n];
93 for (
int n = p + 1;
n < is_prime_size_;
n++) {
94 if (is_prime_[
n])
return n;
101 void CalculatePrimesUpTo(
int max) {
102 ::std::fill(is_prime_, is_prime_ + is_prime_size_,
true);
103 is_prime_[0] = is_prime_[1] =
false;
107 for (
int i = 2;
i*
i <= max; i += i%2+1) {
108 if (!is_prime_[i])
continue;
113 for (
int j = i*i; j <= max; j +=
i) {
114 is_prime_[j] =
false;
119 const int is_prime_size_;
120 bool*
const is_prime_;
126 #endif // GTEST_SAMPLES_PRIME_TABLES_H_ const char * p
Definition: gmock-matchers_test.cc:3613
int i
Definition: gmock-matchers_test.cc:711
constexpr size_t n
Definition: MatrixInversionTest.cpp:14