EASY C++
Intuition\n Describe your first thoughts on how to solve this problem. \ncheck prime number at every step from 2 to n -> brute force\n\n# Approach\n Describe yo
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\ncheck prime number at every step from 2 to n -> brute force\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\ncheck prime and find prime factors accordingly compxty will be reduced\n// Md Arham kalam Ansari\n# Complexity\n- Time complexity: O(sqrt(n)*sqrt(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    bool check_prime(int n)\n    {\n        if(n<=1) return false;\n        for(int i=2;i<=sqrt(n);i++)\n        {\n            if(n%i==0) return false;\n        }\n        return true;\n    }\n    void sol(int &n,vector<int> &v)\n    {\n        \n        while(n%2==0)\n        {\n            v.push_back(2);\n            n=n/2;\n        }\n        for(int i=3;i<=sqrt(n);i=i+2)\n        {\n            while(n%i==0)\n            {\n                v.push_back(i);\n                n=n/i;\n            }\n        }\n        if(n>2) v.push_back(n);\n    }\n    int smallestValue(int n) {\n        vector<int> v;\n        if(n==4) return n;\n        if(check_prime(n)==true) return n;\n        while(check_prime(n)==false)\n        {\n            sol(n,v);\n            int ans=0;\n            for(int i=0;i<v.size();i++) ans+=v[i];\n            //accumulate(v.begin(),v.end(),ans);\n            n=ans;\n            v.clear();\n        }\n        return n;\n    }\n};\n```
['C++']