simple C++ solution


  • 0
    W
    class Solution {
    public:
        int minSteps(int n) {
            int ret = 0;
            while (n > 1) {
                for (int i = 2; i <= n; i++) {
                    if (n % i == 0) {
                        ret += i;
                        n /= i;
                        break;
                    }
                }
            }
            return ret;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.