✳️Two Solution |Factorization is optimized using Sieve of Eratosthenes✅
Intuition\nWe know that product of numbers are always greater than sum of numbers, if the numbers are greater than 1. Hence,  we repeatedly find the sum of the 
# Intuition\nWe know that product of numbers are always greater than sum of numbers, if the numbers are greater than 1. Hence,  we repeatedly find the sum of the factors of a given number until the sum is itself. \n\n\n# Space Complexity: $\\mathcal{O}(1)$\n\n\n# Solution 1\n```\nclass Solution:\n    def smallestValue(self, n: int) -> int:\n        while n != (n:=self.factorization(n)) pass\n        return n\n    \n    def factorization(self, n):\n        factors_sum = 0\n        i = 2\n        while n > 1:\n            while n % i == 0:\n                n //= i\n                factors_sum +=i\n            i += 1\n        return factors_sum\n        \n        \n```\n# Solution 2\nPre-compute a list of prime numbers up to the n using Sieve of Eratosthenes and store them. https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes. This algorithm is a fastest algorithm to find prime factors.\n\nThen use precomputed primes to avoid checking primality of the number during factorization. \n\n# Worst case Space Complexity: $\\mathcal{O}(\\sqrt{n})$\n# Code\n```\nclass Solution:\n    def smallestValue(self, n: int) -> int:\n        self.primes = self.sieve_of_eratosthenes(n)\n        while n != (n:=self.factorization(n)) pass\n        return n\n\n    def factorization(self, n):\n        factors = 0\n        for prime in self.primes:\n            while n % prime == 0:\n                n //= prime\n                factors += prime\n            if n==1: break\n        return factors\n    \n    def sieve_of_eratosthenes(self, n):\n        primes = [True] * (n + 1)\n        primes[0] = primes[1] = False\n        for i in range(2, int(n ** 0.5) + 1):\n            if primes[i]:\n                for j in range(i ** 2, n + 1, i): primes[j] = False\n        return [i for i in range(2, n + 1) if primes[i]]\n        \n```
['Math', 'Python', 'Python3']