Beats 100% || Easy and Simple Solution🔥🔥
Intuition\nBasic intution is find the sum of only those factors which are prime and then replacing it with the initial "n" till the number "n" have no factor ot
# Intuition\nBasic intution is find the sum of only those factors which are prime and then replacing it with the initial "n" till the number "n" have no factor other than 1 and "n", i.e. till "n" becomes prime.\n\n**Every line of code is explained through comments**\n\n\n# Code\n```\nclass Solution {\npublic:\nbool isPrime(int n) // Function to find whether the number is prime or not\n{\n    if(n<=1) return false;\n    for(int i = 2; i<=sqrt(n); i++) //If you have doubt why i have run till sqrt(n) then go through the link [https://www.geeksforgeeks.org/why-do-we-check-up-to-the-square-root-of-a-number-to-determine-if-that-number-is-prime/]\n    {\n        if(n%i==0) return false;\n    }\n    return true;\n}\n\n\n// Function to return sum of all the factors of "n" that are prime.\nint find(int n)\n{\n    int sum =0, i=2;\n    while(n!=1)\n    {\n        if(n%i==0)\n        {\n            if(isPrime(i))  // If the factor is prime then we will add it to sum.\n            {\n                sum+=i;\n            }\n            n/=i;\n            i=1;\n            // after finding a factor we will again find the next factor starting from 2.\n            \n        }\n        i++;\n    }\n    return sum;\n}\n    int smallestValue(int n) {\n\n        //BASE CASE\n//   Why I have taken 1 and 4 as base Case ?\n// --> The factors of 4 are 2 and 2 that are prime whose sum is 4,\n//   and we are replacing n with sum , which will cause an infinite loop.\n//  Similarly with case of 1.\n        if(n==1) return 1;\n        if(n==4) return 4;\n        \n\n        // Replacing the number "n" with the sum of prime factors,till the\n        // number have only 1 and "n" as factor, i.e. till it become prime.\n        while(!(isPrime(n)))\n        {\n            int rep = find(n);\n            n=rep;\n        }\n\n        return n;\n\n    }\n};\n```
['C++']