[C++] Using Sieve
\nclass Solution {\npublic:\n    vector<int> sieve(int n){\n        vector<int> isPrime(n+1, 1);\n        isPrime[0] = isPrime[1] = 0;\n        \n        vector
```\nclass Solution {\npublic:\n    vector<int> sieve(int n){\n        vector<int> isPrime(n+1, 1);\n        isPrime[0] = isPrime[1] = 0;\n        \n        vector<int> prime;\n        for(int i = 2; i <= n; i++){\n            if(isPrime[i]){\n                prime.push_back(i);\n                for(long long j = (long long)i*i; j <= n; j += i) isPrime[j] = 0;\n            }\n        }\n        return prime;\n    }\n    \n    int smallestValue(int n) {\n        /* generate prime numbers less than equal to n */\n        vector<int> primes = sieve(n);\n        \n        while(true){\n            int cur = n;\n            int sum = 0;\n            \n            /* generate prime factors */\n            for(int i = 0; i < primes.size() && primes[i]*primes[i] <= n; i++){\n                while(n % primes[i] == 0){\n                    n /= primes[i];\n                    sum += primes[i];\n                }\n            }\n            sum += (n != 1 ? n : 0);   // if last number is prime itself, it cannot be furthur broken down -> add it\n\n            if(sum == cur) return cur;  // if number was not further decomposable, return it\n            n = sum;\n        }\n        return -1;  // never executes\n    }\n};\n```
['C']