import Control.Monad
f1 x = do
  nx_in <- (return. map (read::String->Int) . words) =<< getLine
  let n:x:[] = nx_in
  if (n==0) && (x==0)
    then return () else do
      print $ f2 n x 1 2
      f1 x
      
f2 n x n1 n2 | n1 == (n-1) = 0
             | n2 == n = f2 n x (n1+1) (n1+2)
             | x-(n1+n2) > n2 && x-(n1+n2) <= n = 1 + f2 n x n1 (n2+1)
             | otherwise = 0 + f2 n x n1 (n2+1)

main = f1 0
