C++||ContestSolution||EasyToUnderstand
Runtime: 3 ms, faster than 75.04% of C++ online submissions for Smallest Value After Replacing With Sum of Prime Factors.\nMemory Usage: 5.9 MB, less than 95.21
Runtime: 3 ms, faster than 75.04% of C++ online submissions for Smallest Value After Replacing With Sum of Prime Factors.\nMemory Usage: 5.9 MB, less than 95.21% of C++ online submissions for Smallest Value After Replacing With Sum of Prime Factors.\n\nclass Solution {\npublic:\n    \n    int primeFactor(int n){\n        int sum=0;\n        for(int i=2;n>1;i++){\n            while(n%i==0){\n                sum=sum+i;\n                n=n/i;\n            }\n        }\n            return sum;\n    }\n    int smallestValue(int n) {\n        \n        int sum=primeFactor(n);\n        if(sum == n)\n            return sum;\n        else\n            return smallestValue(sum); \n\t\t\t\n    }\n};
['Math', 'C']