seminar04 simplified 03_factorization

master
nihonium 2 years ago
parent 5165d16ffa
commit 1d5f2cac48
No known key found for this signature in database
GPG Key ID: 0251623741027CFC

@ -5,8 +5,6 @@
using std::cout, std::endl, std::pair, std::vector;
int next_prime(int n);
vector<pair<int, int>> factorization(int n) {
if (n == 1) {
return vector<pair<int,int>>{{1, 1}};
@ -23,31 +21,11 @@ vector<pair<int, int>> 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<int>(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<int,int> p) {
out << "{" << p.first << ", " << p.second << "}";
return out;