C++, Fully explained 5 line code
Intuition\nFirst thought is to solve with the help of bool prime and so on, but recursively we don\'t need to find the prime. \n# Approach\n Describe your appro
# Intuition\nFirst thought is to solve with the help of bool prime and so on, but recursively we don\'t need to find the prime. \n# Approach\n<!-- Describe your approach to solving the problem. -->\nFirst calculate all the prime factor of the number, then sum all of it.\nThen u recursively pass the sum to our function, and check if the sum is equal to previously existing number.\nFor ex :\nWe take 15 -\nfactors are - 3 ,5,15\nprime no are - 3,5\nsum is 8.\n\nnow we have to find out the prime factor of 8.\nwhich is 2, 2 ,2.\nsum is 6.\n\nagain we pass 6 as we know 8 != 6.\nprime factor of 6 = 2,3\nsum is 5.\n\nagain we pass 5, because 5 != 6.\n5 is prime number. prime factor = 5 only.\n\nwe pass 5 again which stisfy the condition, 5==5\nHence base case satisfied we return 5 as the answer.\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\no(n)\n\n# Code\n```\nclass Solution {\npublic:\nint check(int n){\n    int sum = 0;\n        int c = 2; \n        while(n > 1){\n            if(n % c == 0){\n                sum += c;\n                n /= c;\n            }\n            else{\n                c++;\n            }\n        }\n      return sum;\n}\n\n    int smallestValue(int n) {\n         int ans=check(n);\n        if(ans==n) return ans;\n        else return smallestValue(ans);\n    }\n};\n```
['C++']