adding prime factor algorithm