Exception handling solution java
Intro\nProblem isn`t hard, so only one problem that i had is stackoverflow\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nYeah, yo
# Intro\nProblem isn`t hard, so only one problem that i had is stackoverflow\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nYeah, you can make it faster by making 1 more check. But stackOverflow helped me alot in my life so i decided to leave it here^_^ss\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: 959 ms\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: 466.4 MB\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public static int smallestValue(int n) {\n        try {\n            int sum=0;\n            int prev = n;\n            for (int i = 2; i <= Math.sqrt(n); i++) {\n                if (n%i==0){sum+=i; n/=i;i--;}\n            }\n            if (sum==0) return n;\n            return smallestValue(sum+n);\n        } catch (StackOverflowError a) {return n*2;}\n    }\n}}\n}\n```
['Java']