Optimize Factoring Algorithm