Nice problem... not usually built in to the language but important for many applications (factoring, e.g.).
Once again, a naive algorithm is not hard to specify. [Step 1]