def sieve(n) eSieve = (2..n).to_a i = 0 pbar = ProgressBar.new("sieving", n) while i < Math.sqrt(n) j = i + 1 while (j < eSieve.length) if (eSieve[j] > (i ** 2)) and ((eSieve[j] % eSieve[i]) == 0) eSieve.delete_at j pbar.inc end j += 1 end i += 1 pbar.set(i + (n-eSieve.length)) end pbar.finish eSieve end eSieve = sieve(600851475143) def isPrime(n) eSieve.contains(n) end puts isPrime(7) factors = [] for i in 1..600851475143 if (600851475143 % i) == 0 if isPrime(600851475143 % i) factors << i end end end