Python 3   ||   10 lines,  recursion, w/ brief explanation   ||   T/S: 42% / 90%
\nclass Solution:\n    def smallestValue(self, n):\n\n        prev, ans = n, 0\n\n        while not n%2:                  # 2 is the unique even prime\n        
```\nclass Solution:\n    def smallestValue(self, n):\n\n        prev, ans = n, 0\n\n        while not n%2:                  # 2 is the unique even prime\n                ans += 2\n                n//= 2\n\n        for i in range(3,n+1,2):        #  <\u2013\u2013 prune even divisors...\n                while not n%i:\n                    ans += i\n                    n//= i\n\n        return self.smallestValue(ans) if ans != prev else ans\n```\n[https://leetcode.com/problems/smallest-value-after-replacing-with-sum-of-prime-factors/submissions/1290506391/](https://leetcode.com/problems/smallest-value-after-replacing-with-sum-of-prime-factors/submissions/1290506391/)\n\n\nI could be wrong, but I think that time complexity is *O*(sqrt *N* * log *N*) and space complexity is *O*(log *N*), in which *N* ~ `n`.\n
['Python', 'Python3']