Algorithm to find factors of a number