int m = n; while (m > 1) m = sqrt(m) // truncates down to an integer Try it for a few random numbers, such as my favorite random number, 65536.