Factorize and correction to miller-rabin test