/*
* divide the coin which the users input in with the square coins
**/
#include
#include
int min(int x,int y){
if (x else return y;
}
int low(int x) /*x>=0,返回一个小于等于x的最大平方数*/
{
int k=sqrt(x)/1;
k*=k;
return k;
}
int divide(int m,int n)/*m>=n,且其它函数调用时要求m,n>0,递归调用时要求m,n>=0*/
{
int k1,k2;
if(n==1||m==0) return 1;
k1=min(n,low(m-n));
k2=(sqrt(n)-1)*(sqrt(n)-1);
return divide(m-n,k1)+divide(m,k2);
}
main()
{
int m,sum;
while(1)
{
printf("Please input a positive integer number:");
scanf("%d",&m);
if(m>0) break;
else printf("Error!");
}
sum=divide(m, min( 17*17,low(m) ) );
printf("There are %d kinds of method of dividing the number %d;\n",sum,m);
getch();
}