Square-free integers: Difference between revisions
m
C++ - renamed class
m (Minor edit to C++ code) |
m (C++ - renamed class) |
||
Line 349:
#include <iostream>
#include <string>
#include "
using integer = uint64_t;
bool square_free(const
if (n % 4 == 0)
return false;
Line 363:
}
void print_square_free_numbers(const
std::cout << "Square-free numbers between " << from
<< " and " << to << ":\n";
Line 382:
}
void print_square_free_count(const
integer count = 0;
for (integer i = from; i <= to; ++i) {
Line 393:
int main() {
print_square_free_numbers(sieve, 1, 145);
print_square_free_numbers(sieve, 1000000000000LL, 1000000000145LL);
Line 404:
}</lang>
Contents of
<lang cpp>#ifndef
#define
#include <algorithm>
Line 415:
* See https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes.
*/
class
public:
explicit
bool is_prime(size_t) const;
private:
Line 428:
* @param limit the maximum integer that can be tested for primality
*/
inline
limit = std::max(size_t(3), limit);
is_prime_.resize(limit/2, true);
Line 448:
* @return true if the integer is prime
*/
inline bool
if (n == 2)
return true;
|