Start the algorithm with a number (referred to as "N") to be factored, a list of prime numbers in ascending order and an empty list that will be called the factor list. If N is in the prime list, then it is a prime number (and is therefore not factorable). The algorithm starts by trying to divide two (the first prime) into N.
Set the limit that stops the algorithm by determining the square root of N. The first prime greater than the square root will be the limit. The algorithm checks at each step to see if the prime being considered is below the limit. If the prime is equal to or greater than the limit, the algorithm stops and the factor list contains the factors. Each time a new factor is found, a new square root and a new limit should be computed.
Continue the algorithm until it is time to stop. If it is not time to stop the algorithm, try to divide the current prime into N. If it does not divide, start the next step with the next higher prime on the list. If a prime cannot be divided into N, add that prime to the factor list and compute a new N. The new N will be the old N divided by the prime that divided the old N. Continue the algorithm with the new N and the next prime. For example, if you are factoring 2,431 and just discovered that 11 divides into 2,431, add 11 to the factor list and compute the new N as 2,431/11 = 195. Continue with N = 195 and the next prime after 11 (the current prime will now equal 13). The square root of 195 is just under 14, so the next limit is the next prime over 14, which is 17.