C++ || JavaScript || Easy Solution
Complexity\n- Time complexity: O(sqrt(n))\n\n- Space complexity: O(1)\n\n\n# Code\n# C++\n\nclass Solution {\npublic:\n    int findAns(int n){\n        int div=
# Complexity\n- Time complexity: O(sqrt(n))\n\n- Space complexity: O(1)\n\n\n# Code\n# C++\n```\nclass Solution {\npublic:\n    int findAns(int n){\n        int div=2,ans=0;\n        while(n%2==0){\n            ans+=2;\n            n/=2;\n        }\n        int res=sqrt(n);\n        for(int i=3;i<=res;i+=2){\n            while(n%i==0){\n                ans+=i;\n                n/=i;\n            }\n        }\n        if(n>2) ans+=n;\n        return ans;\n    }\n    int smallestValue(int n) {\n        while(1){\n            int ans=findAns(n);\n            if(ans==n) return n;\n            n=ans;\n        }\n        return n;\n    }\n};\n```\n\n---\n\n# JavaScript\n```\n/**\n * @param {number} n\n * @return {number}\n */\nvar smallestValue = function(n) {\n    const findAns=(n)=>{\n        let ans=0;\n        while(n%2==0){\n            ans+=2;\n            n/=2;\n        }\n        let res=Math.sqrt(n);\n        for(let i=3;i<=res;i+=2){\n            while(n%i==0){\n                ans+=i;\n                n/=i;\n            }\n        }\n        if(n>2) ans+=n;\n        return ans;\n    }\n    while(1){\n        let ans=findAns(n);\n        if(ans==n) return n;\n        n=ans;\n    }\n    return n;\n};\n```
['Math', 'Number Theory', 'C++', 'JavaScript']