require 'prime'

### constant

MAX_N = 123456
MAX_N2 = 2 * MAX_N

### main

psums = [0]
for k in (1..MAX_N2)
  psums[k] = Prime.prime?(k) ? psums[k - 1] + 1 : psums[k - 1]
end

loop do
  n = gets.to_i
  break if n == 0

  puts psums[2 * n] - psums[n]
end