From 1d5f2cac48515447586550800f57d71a6a362a20 Mon Sep 17 00:00:00 2001 From: nihonium Date: Wed, 9 Nov 2022 19:31:05 +0300 Subject: [PATCH] seminar04 simplified 03_factorization --- seminar04_templates/03_factorization/main.cpp | 24 +------------------ 1 file changed, 1 insertion(+), 23 deletions(-) diff --git a/seminar04_templates/03_factorization/main.cpp b/seminar04_templates/03_factorization/main.cpp index fde4487..990b5eb 100644 --- a/seminar04_templates/03_factorization/main.cpp +++ b/seminar04_templates/03_factorization/main.cpp @@ -5,8 +5,6 @@ using std::cout, std::endl, std::pair, std::vector; -int next_prime(int n); - vector> factorization(int n) { if (n == 1) { return vector>{{1, 1}}; @@ -23,31 +21,11 @@ vector> factorization(int n) { } if (c) result.push_back(pair{d, c}); - d = next_prime(d); + d++; } return result; } -bool is_prime(int n) { - bool prime = true; - for(int i = 2; i <= static_cast(std::sqrt(n)); i++) { - if (n % i == 0) { - prime = false; - break; - } - } - return prime; -} - -int next_prime(int n) { - ++n; - while (true) { - if (is_prime(n)) - return n; - ++n; - } -} - std::ostream& operator<<(std::ostream& out, pair p) { out << "{" << p.first << ", " << p.second << "}"; return out;