Simplest Recursion
Intuition\n Describe your first thoughts on how to solve this problem. \nThe idea is very simple. We recursively call factorial function which calculates the su
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe idea is very simple. We recursively call `factorial` function which calculates the sum of factorial and pass it to the `smallestValue`  function.\nThe only problem we will face is when sum of factorial be equal to the number `n` so we handle the case by using the `if` clause.\n\n\n# Code\n```\nclass Solution {\n    int a = 2;\n    public int smallestValue(int n) {\n        int sum = factorial(n,2);\n        // handle the anamoly\n        if(sum == n)\n            return n;\n        return smallestValue(sum);\n    }\n    public static int factorial(int n , int a){\n        if (n == 1) return 0;\n\n        if(n%a == 0) return a + factorial(n/a, a);\n        else return factorial(n, a+1);\n\n    }\n}\n```
['Java']