MAX = 1_000_000

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

sqrt_n = Math.sqrt(MAX).ceil
(2..sqrt_n).each do |i|
  j = i*i
  loop do
    is_prime[j] = false
    j += i
    break if j > MAX
  end
end

prime_count_list = [0, 0]
count = 0
2.upto(MAX) do |i|
  count += 1 if is_prime[i]
  prime_count_list[i] = count
end

while num = gets.to_i
  return if num == 0
  puts prime_count_list[num]
end