#include<stdio.h>
#include<string.h>

int c,sq[18];

int count(int n,int i){
	if(n==0)return 0;
	int j;
	for(j=i;j>=1;j--){
		if(n<sq[j])continue;
		if(n==sq[j]){
			++c;
			continue;
		}
		count(n-sq[j],j);
	}
	return 0;
}

int main(){

	int i,j,n;
	
	for(i=0;i<=17;i++){
		sq[i]=i*i;
	}
	
	while(0<=scanf("%d",&n)){
		if(n==0)break;
		c=0;
		
		for(i=1;i<=17;i++){
			if(n<sq[i]){
				--i;
				break;
			}
		}
		count(n,i);
		printf("%d\n",c);
	}
	return 0;
}