Max=123456*2+1

a=Array.new Max
a[0]=a[1]=false
a[2]=true
index=4
while index<a.length
	a[index] = false
	index+=2
end
1.upto(Max/2-1){|i|
	num=i*2+1
	if a[num] == nil
		a[num] = true
		index = num*2
		while index < Max
			a[index]=false
			index+=num
		end
	end
}

while true
	n=gets.to_i
	break if n == 0

	count = 0
	i = n+1
	while i <= 2*n
		count += 1 if a[i]
		i+=1
	end
	p count
end