diff options
author | Ta180m | 2020-05-21 16:47:58 -0500 |
---|---|---|
committer | Ta180m | 2020-05-21 16:47:58 -0500 |
commit | 7d90c62718119dab5002856179c20a45014b30ba (patch) | |
tree | 0b13b26234cd48b45495e6b790dea9982713bbd3 /Math | |
parent | 703363d5abfe07cf43533b37be625832df9180da (diff) |
Update primes.cpp
Diffstat (limited to 'Math')
-rw-r--r-- | Math/primes.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Math/primes.cpp b/Math/primes.cpp index 6df51ba..e3ba48d 100644 --- a/Math/primes.cpp +++ b/Math/primes.cpp @@ -17,14 +17,17 @@ bool is_prime(ll N) { return true; } -vector<int> pf(ll N) { - vector<int> factors; +vector<ii> factorize(ll N) { + vector<ii> factors; ll idx = 0, pf = pr[idx]; while (N != 1 && pf * pf <= N) { - while (N % pf == 0) { N /= pf; factors.push_back(pf); } - pf = pr[++idx]; + if (N % pf == 0) { + factors.emplace_back(pf, 0); + while (N % pf == 0) { N /= pf; ++factors.back().s; } + pf = pr[++idx]; + } } - if (N != 1) factors.push_back(N); + if (N != 1) factors.emplace_back(N, 1); return factors; } |