primes = []
2.upto(123456*2){|x|
    prime = true
    2.upto(Math.sqrt(x)){|y|
        if x % y == 0
            prime = false
            break
        end
    }
    primes << x if prime
}

arr = Array.new(123456 * 2 + 1 , 0)
primes.each{|prime| arr[prime] = 1}
1.upto(arr.length - 1){|i| arr[i] += arr[i - 1]}

while true
    n = gets.to_i
    break if n == 0
    puts arr[n * 2] - arr[n]
end
