require 'prime'

### constant

MAX_T = 30000;
MAX_SIDE = (MAX_T - 1) / 2;

### main

pnums = Prime.each(MAX_SIDE).map{|pn| pn}
#p pnums

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

  count = 0
  mina = t / 3
  maxside = (t - 1) / 2
  
  for a in pnums
    next if a < mina
    break if a > maxside
    for b in pnums
      break if b > a
      c = t - (a + b)
      if c > 0 && c <= b && Prime.prime?(c)
        #p [a, b, c]
        count += 1
      end
    end
  end

  p count
end