Java | Easy to understand solution  + Comments | 5 ms solution
\nclass Solution {\n    public int smallestValue(int n) {\n        while(true){\n            int sum = sumOfPrimeFactors(n);\n            if(sum == n) break; //
```\nclass Solution {\n    public int smallestValue(int n) {\n        while(true){\n            int sum = sumOfPrimeFactors(n);\n            if(sum == n) break; //if sum and n both becomes equal than break the loop\n            n = sum; //update n with sum of its prime factors\n        }\n        \n        return n;\n    }\n    \n    public int sumOfPrimeFactors(int num){\n        int factor = 2;\n        int sum = 0;\n\n        while(num != 1){ //Repeat the loop till number becomes 1.\n            if(num % factor == 0){ //Check if factor divides the number.\n                num /= factor; //If yes, update the number.\n                sum += factor; //Add factor to sum.\n                continue;\n            } \n            \n            factor++; //If the current number is not a factor, check the next number.\n        }\n        return sum;\n    } \n} \n\n\n```
['Java']