Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int GetFactorization(int n) {
- int cnt = 0;
- // find the number of 2s that will divide 'n'
- while (n % 2 == 0) {
- cnt++;
- n /= 2;
- }
- // find the other factors of 'n' (skip the even numbers since we already divided it by 2 previously)
- for (int i = 3; i <= (int) sqrt(n); i += 2) {
- while (n % i == 0) {
- cnt++;
- n /= i;
- }
- }
- // if 'n' is still greater than 1, then increment 'cnt' (it means 'n' is a prime number)
- if (n > 1) {
- cnt++;
- }
- return cnt;
- }
- int main() {
- int n;
- cin >> n;
- int cnt = GetFactorization(n);
- cout << cnt << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment