include Math
while line = gets do
  a,other = line.split.map(&:to_i)
  if(a == 0)
    break
  end
  count = 0
  i = a + 1
  if (i % 2 == 0)
    i += 1
  end
  while i <= a * 2
    j = 3
    flag = true
    while j < i / 2
      if(i % j == 0)
        flag = false
        break
      else
        j += 2
      end
    end
    if(flag == true)
      count += 1
    end
    i += 2
  end
  puts count
end