require 'prime'

until (n=gets.to_i)==0
  min, max = [n/2, (n+1)/2]
  
  cnt = 0
  while min >= 3
    if Prime.prime?(min) && Prime.prime?(max)
      cnt += 1
    end

    min -= 1
    max += 1
  end

  cnt += 1 if Prime.prime?(n-2)

  puts cnt
end