Square Coins
#include"iostream"
using namespace std;
int c1[310],c2[310];
int main()
{
int i,j,k,nNum;
while(scanf("%d",&nNum),nNum)
{
for(i=0;i<=nNum;++i)
{
c1[i]=1;
c2[i]=0;
}
for(i=2;i*i<=nNum;++i)//注意i和k处有所改动;
{
for(j=0;j<=nNum;++j)
for(k=0;k+j<=nNum;k+=i*i)
c2[k+j]+=c1[j];
for(j=0;j<=nNum;++j)
{
c1[j]=c2[j];
c2[j]=0;
}
}
printf("%d\n",c1[nNum]);
}
return 0;
}