c++ solution 100% beats rate
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    bool isprime(int n) {
        if (n == 1) return false;
        for (int i = 2; i <= sqrt(n); i++) {
            if (n % i == 0)
                return false;
        }
        return true;
    }

    int smallestValue(int n) {
        if (isprime(n)) return n;
        int sum = 0;
        //kaam
        for (int i = 1; i < sqrt(n); i++) {
            if (n % i == 0 && isprime(i)) {
                int m=n;
                while(m%i==0){
                sum += i;
                m /= i;
            }
        }
    }
     for (int i = sqrt(n);i>=1; i--) {
            if (n % i == 0 && isprime(n/i)) {
                int m=n;
                while(m%(n/i)==0){
                sum += (n/i);
                m /= (n/i);
            }
        }
     }
        if (sum == 4) return 4;
        return smallestValue(sum);
    }
};

```
['C++']