module Main where
import           Data.Maybe

main :: IO ()
main = interact (unlines . map (show . length . sumPrimes 2) . takeWhile (/= 0) . map read . lines)

sumPrimes :: Integer -> Integer -> [[Integer]]
sumPrimes 1 n = [[n] | n `elem` takeWhile (<= n) primes]
sumPrimes k n = [p : rs | (p, q) <- zip ps qs, rs <- sumPrimes (k - 1) q]
  where ps = takeWhile (<= n `div` k) primes
        qs = map (n -) ps

primes :: [Integer]
primes = 2 : 3 : go 3 []
  where go x xs = y : go y (x : xs)
          where y = fromJust $ listToMaybe [ n | n <- [x + 2, x + 4 ..]
                                               , all (\m -> n `mod` m /= 0) $ ms n]
                ms n = dropWhile (floor ((sqrt :: Float -> Float) (fromInteger n)) <) xs