module Memoizable
	def memoize(name)
		original = "__original_#{name}__"
		([Class, Module].include?(self.class) ? self : self.class).class_eval {
			alias_method(original, name)
			private(original)
			cache = {}
			define_method(name){|*args|
				cache[args] ||= send(original, *args)
			}
		}
	end 
end

include Memoizable

def f(n, k)
	if n <= 0
		return n == 0 ? 1 : 0
	end
	if k == 17
		return n % 289 == 0 ? 1 : 0
	end
	f(n, k+1) + f(n-k*k, k)
end

memoize :f
	
loop {
	n = gets.to_i
	break if n == 0
	p f(n, 1)
}