Q:

Find three numbers that are divisors of given number and their sum is minimal

I'm trying to work this problem for over a day and I can't come with a reasonable solution. I think this is a fairly easy programming question and more of an algorithmic question. We have one given number N, (1< N<10^9) and we have to find three numbers M,P,Q so they satisfy M×P×Q=N and their sum is minimal (the smallest possible).I came up with this code but it does not work for all numbers in range(for example for 6). I try to find the biggest divisor closest to third root of N. The program works for most of the numbers but not for all. And i wonder if while is the best approach or I should for or other cycle. Thank you in advance! Have a great day!
P.S. some examples - 100 = 4×5×5, 121 = 11×11×1, 8 = 2×2×2, 400 = 8×5×10, 1000 = 10×10×10,4000=16×10×25 and so on.
int main() {
    int m = 0, n = 0, p = 0, q = 0, i = 0;;
    std::cin >> n;
    i = int(std::cbrt(n));
    while (true) {
        int ten = std::cbrt(n);
        if (pow(ten, 3) == n) {
            m = ten;
            p = ten;
            q = ten;
            break;
        }
        int square = n;
        if (i * i == square) {
            n = i;
            m = i;
            p = i;
            break;
        }
        if (i == 1) {
            m = n;
            p = 1;
            q = 1;
            break;
        }
        if (n % i == 0) {
            n = n / i;
            m = i;
            p = n;
            break;
        }
        i++;
    }
    i = std::cbrt(n);
    while (true) {
        int ten = std::cbrt(n);
        if (pow(ten, 3) == n) {
            m = ten;
            p = ten;
            q = ten;
            break;
        }
        int square = n;
        if (i * i == square) {
            p = i;
            q = i;
            break;
        }
        if (i == 1) {
            q = 1;
            break;
        }
        if (n % i == 0) {
            q = n / i;
            p = i;
            break;
        }
        i++;
    }
    std::cout << m << " " << p << " " << q << std::endl;
    return 0;
}

A:

I found your idea interesting. First looking for a divider close to the cubic root. Then, in a second step, looking for divider close to the square root of the remaining.
The following code seems to work for the cases you cited, including the input of 6. 
I mainly tried to simplify your code, removing code that looks odd and do not seem useful. I also insure that the second step was effectively trying to search for a factor close to the square root of the remaining, there was a little error on that. 
I did not try to improve the speed of the program. I guess the first step is to test the validity of the algorithm. In a second step, as proposed in a comment, it could be possible to use the prime factors of the input to fasten the program, while keeping the same strategy.
Here, complexity is O(n) in the worst case, which seems quite good already. 
EDIT:
To fasten the program a little bit, I tried to loop in the negative order (i-- instead of i++). I checked that for was no difference on the tests you proposed. However, for one additional test that I performed, I obtained a gain ...
For n = 124267948, I now obtain (316, 56179, 7) sum = 56502 instead of (553, 4, 56179) sum = 56736. 
This implies that some further tests and analysis are really needed before validating the algorithm. 
**Edit 2: **
I made systematic tests for n between 1 and 1e6, and compared the two variants (i++ and i--). They often provide the same result, elsewhere one or the other is better. Further investigation is needed. 
Edit 3:
I made a systematic comparison, with a optimal scheme that considers all possible value for first divider (m) and then looks for a divider near the sqrt of the remainder (n/m). I got that this optimal scheme is often better than the two others. For example for n=44. This optimal scheme is more complex, but computation time seems to stay rather short. 
#include    <iostream>
#include    <cmath>

int main() {
int m = 0, n = 0, p = 0, q = 0, i;
bool end = false;
std::cin >> n;
i = int(std::cbrt(n));
//std::cout << "cbrt(n) = " << i << "\n";

if (n == 1) {
    m = p = q = 1;
    end = true;
} else {
    if (i == 1) i = 2;
    if (pow(i, 3) == n) {
         m = i;
         p = i;
         q = i;
         end = true;    
    }
}

if (!end) {

//  1st step: research of a factor almost equal to a cubic root
    i++;
    while (true) {
        if (n % i == 0) {
            n = n / i;
            m = i;
            break;
        }
        i--;
    }

 // 2nd step: research of factor almost equal to the sqrt 
    i = std::sqrt(n) + 1;

    //std::cout << "before square search: n = " << n  << "\ti = " << i << "\n";
    while (!end) {  
        if (n % i == 0) {
            p = i;
            q = n/i;
            end = true;
        }
        i--;
    }
}

    std::cout << m << " " << p << " " << q << std::endl;
    return 0;
}

