Beats 100% in C++
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){
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0) return false;
    }
    return true;
  }
   int sumofprimes(int n){
      int sum=0;
      for(int i=2;i<sqrt(n);i++){
        if(n%i==0 and 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 and isprime(n/i)){
            int m=n;
            while(m%(n/i)==0){
                sum+=(n/i);
                m/=(n/i);
            }
        }
      }
      return sum;
   }
    int smallestValue(int n) {
        if(isprime(n)) return n;
        n=sumofprimes(n);
        if(n==4) return n;
        return smallestValue(n);
    }
};
```
['C++']