prime factorization and gambler ruin