Refactor use for loop to solved Primes 8