MAX = 1_000_000

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

sqrt_n = Math.sqrt(MAX).ceil
(2..sqrt_n).each do |i|
  next unless is_prime[i]
  (i*i).step(by: i, to: MAX) do |j|
    is_prime[j] = false
  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
  break if num == 0
  puts prime_count_list[num]
end