Jump to content

Strong and weak primes: Difference between revisions

m
C++ - made function definitions out of line
(Added Swift solution)
m (C++ - made function definitions out of line)
Line 317:
public:
explicit prime_info(int max) : max_print(max) {}
void add_prime(int prime);
 
void add_primeprint(intstd::ostream& primeos, const char* name) {const;
++count2;
if (prime < limit1)
++count1;
if (count2 <= max_print) {
if (count2 > 1)
out << ' ';
out << prime;
}
}
void print(std::ostream& os, const char* name) const {
os << "First " << max_print << " " << name << " primes: " << out.str() << '\n';
os << "Number of " << name << " primes below " << limit1 << ": " << count1 << '\n';
os << "Number of " << name << " primes below " << limit2 << ": " << count2 << '\n';
}
private:
int max_print;
Line 340 ⟶ 325:
std::ostringstream out;
};
 
void prime_info::add_prime(int prime) {
++count2;
if (prime < limit1)
++count1;
if (count2 <= max_print) {
if (count2 > 1)
out << ' ';
out << prime;
}
}
 
void prime_info::print(std::ostream& os, const char* name) const {
os << "First " << max_print << " " << name << " primes: " << out.str() << '\n';
os << "Number of " << name << " primes below " << limit1 << ": " << count1 << '\n';
os << "Number of " << name << " primes below " << limit2 << ": " << count2 << '\n';
}
 
int main() {
1,777

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.