C++ || Commented-Code
class Solution {\npublic:\n    \n    //* Function to create a hash array for prime numbers till n *.\n    vector hashprime(int n){\n        vector arr(n,0);\n\n
class Solution {\npublic:\n    \n    //**** Function to create a hash array for prime numbers till n ****.\n    vector<int> hashprime(int n){\n        vector<int> arr(n,0);\n\n        for(int i = 0 ; i < n ; i++){\n            arr[i] = i;\n        }\n        arr[0] = arr[1] = 0;\n        for(int i = 2 ; i < n ; i++){\n            if(arr[i] != 0){\n                for(int ind = i+i; ind < n ; ind += i){\n                    arr[ind] = 0;\n                }\n            }\n        }\n\n        return arr;\n    }\n    \n    int smallestValue(int n) {\n        int ans = n;\n        \n        vector<int> hash = hashprime(n+1); \n        \n        // while hash is not a prime number we will iterate.\n        \n        while(!hash[ans]){\n            \n            int newno = 0; // Variable to store the sum of prime factors.\n            \n            // storing current number to maintain the for loop in next line.\n            int sz  = ans;\n            \n            for(int i = 2 ; i  <= sz/2; i++){\n                while(ans%i == 0){\n                    newno += i;\n                    ans /= i;\n                }\n            }\n            \n        // if the number is equal to the sum of its prime factors then return in order to avoid infinite loop.\n            if(sz == newno)\n                return newno;\n            \n            // replace original number with sum of its prime factors.\n            \n            ans = newno;\n            \n        }\n        \n        return ans;\n    }\n};
['C']