candidate_prime = 5 while candidate_prime < 1000 divisor = 2 found = false while divisor < candidate_prime if candidate_prime.modulo(divisor) == 0 found = true break end divisor = divisor + 1 if divisor * divisor > candidate_prime break end end if !found puts candidate_prime end candidate_prime = candidate_prime + 1 end
candidate_prime = 5 while candidate_prime < 1000 divisor = 2 while divisor * divisor <= candidate_prime && candidate_prime.modulo(divisor) != 0 divisor += 1 end puts candidate_prime if divisor * divisor > candidate_prime candidate_prime += 1 end