max = 1_000_000

is_prime = [false, false] + [true]*(max -1)

loop_max = Math.sqrt(max).to_i + 1

2.upto(loop_max) do |i|
  next unless is_prime[i]
  (i*i).step(max, i) do |j|
    is_prime[j] = false
  end
end

count = 0
prime_num_list = (0..max).map do |i|
  count += 1 if is_prime[i]
  count
end

while n = gets.to_i
  break if n == 0
  puts prime_num_list[n]
end