semeru/Code-Code-CloneDetection-POJ104 huggingface dataset:
/*???2011?11?28?
 *??????
 *????putapple.cpp
 *???
 */


int main()
{
	int n = 0, plate = 0, apple = 0;				//???????????n?????plate????apple
	int putapple(int, int);							//????putapple??????????plate?????
													//apple???????????
	cin >> n;										//??????n
	for (int i = 0; i < n; i++)
	{
		cin >> apple >> plate;						//??????plate????apple
		if (plate <= 0)								//????????????
		{
			cout << "Error!" << endl;
			continue;
		}
		cout << putapple(apple, plate) << endl;		//??????????putapple????????
	}
	return 0;
}


//???putapple???????
int putapple(int apple, int plate)
{
	if (apple < 0)									//???????????0???
		return 0;
	else if (plate == 1)							//??????1???????
		return 1;
	else											//?????????????
		return putapple(apple - plate, plate) + putapple(apple, plate - 1);
													//??????????
													//???????????????????putapple(apple-plate, plate)?
													//?????????????????0
}													//??????????????????????putapple(apple, plate-1)?
													//??????????????
int main()
{
	int n,m;
	int i,t;
	int method(int n,int m);
	
	scanf("%d",&t);

	for(i=0;i<t;i++)
	{
		scanf("%d%d",&m,&n);
		printf("%d\n",method(n,m));
	}

	return 0;
}
int method(int n,int m)
{
	int sum=0;
	if(n==1||m==1||m==0)
		return 1;
	else if(n>m)
		sum+=method(n-1,m);
	else
		sum+=method(n-1,m)+method(n,m-n);
	return sum;
}
int num=0;
int sol(int M,int N)
{
     if (N==1||M==0||M==1)
         return 1;
     else if (M>=N)
         return sol(M,N-1)+sol(M-N,N);
     else
         return sol(M,N-1);
}    
int main()
{
     int t, i, M, N;
     cin >> t;
     for (i=1;i<=t;i++)
     {
         cin >> M >> N;
         cout << sol(M, N) << endl;
     }
     return 0;
}
int M,N;
 
int apple(int num,int m)
{
	int i,a;
    int sum=0;
	if(num==0)
	    return sum;
	

	else
	{	if(m>num)  
		for(i=num;i>0;i--)
		{	a=m-i;
			sum+=apple(i,a);
		}
        else
		{
			sum+=1;
			num=m-1;
			sum+=apple(num,m);
		} 
		return sum;
	}
}





int main()
{
	int t,i;

	scanf("%d",&t);

	for(i=0;i<t;i++)
	{
    int total=0;
	scanf("%d",&M);
	scanf("%d",&N);

    total=apple(N,M);

	printf("%d\n",total);
	}

	return 0;
}
int k=0;
int apple( int m, int n );
int main()
{
	int t,i,M[20],N[20];
	cin>>t;
	for ( i=0 ; i<t ; i++ )
	{
		cin>>M[i]>>N[i];
		cout<<apple( M[i],N[i] )<<endl;
	}
	return 0;
}
int apple( int m, int n )
{
	if ( n==1||n==0 )
	{
		return 1;
	}
	if ( m>=n )
	{
		return apple( m,n-1 )+apple( m-n,n );
	}
	if ( m<n )
	{
		return apple( m,n-1 );
	}
	
}
int q(int m,int n)
{
 int c;
 if(m<0){ return 0;}
 if(n==1){ return 1;}
 else
 {c=q(m,n-1)+q(m-n,n);
}   
  return(c);  
}
main()
{
 int t,i,k,n,m;
 scanf("%d",&t);
 for(i=0;i<t;i++)
 {
   scanf("%d %d",&m,&n);
   k=q(m,n);
   printf("%d\n",k);              
 }
 getchar();
 getchar();
 getchar();      
}
int m,n;

int find(int a,int b,int c)
{
    int i,k,l,t,s,p,q;
    if (b==1) return 1;
    k=0;
    t=a/b;
    for (i=c;i<=t;i++)
        k=k+find(a-i,b-1,i);
    return k;
}

int main()
{
    int k=0;
    int t,i;
    cin >>t;
    for (i=1;i<=t;i++)
    {
        cin >>m >>n;
        k=find (m,n,0);
        cout << k <<endl;
    }
    return 0;
}
int placeMethod(int a, int b);
int main()
{
	int n, a, b, num;
	cin >> n;
	while(n--)
	{
		cin >> a >> b;
		num = placeMethod(a, b);
		cout << num << endl;
	}
	return 0;
}
int placeMethod(int a, int b)
{
	int sum;
	if(a==0)
		return 1;
	if(b==1)
		return 1;
	if(a<b)
		return placeMethod(a, b-1);
	else
		return  placeMethod(a-b,b) + placeMethod(a, b-1);

}
//********************************
//*????????   **
//*?????? 1300012855 **
//*???2013.11.27  **
//********************************


int putapple(int apple,int basket); // ??????
int main(void)
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int apple, basket;
		cin >> apple >> basket;
		cout << putapple(apple, basket) << endl;
	}
	return 0;
}

int putapple(int apple,int basket)
{
	if(apple < 0) return 0; // ??apple <0 ????????
	if(basket == 1) return 1; // ??basket == 1 ????????? 

	// ????????????
	int situation1 = putapple(apple, basket - 1);

	// ?????????
	int situation2 = putapple(apple - basket, basket);
	return situation1 + situation2; // ????????
}
int f(int m,int n)
{   if(m<0||n<0) return(0);
	
	else if(n==1) return(1);
   else if(m==1) return(1);
   else if(m==0) return(1);
   else return(f(m,n-1)+f(m-n,n));
}
int main()
{
	int t;
	int i;
	int m,n;
	scanf("%d",&t);
	for(i=0;i<t;i++)
	{ scanf("%d %d",&m,&n);
	printf("%d\n",f(m,n));
	}
	return 0;
}
int ways(int,int);
int main()
{
	int t,m,n;
	cin>>t;
	while(t--)
	{
		cin>>m>>n;
		cout<<ways(m,n)<<endl;
	}
	return 0;
}
int ways(int m,int n)
{
	int sum=0;
	if(n==1)sum=1;
	else if(m<0)sum=0;
	else if(m==0)sum=1;
	else sum=sum+ways(m,n-1)+ways(m-n,n);
	return sum;
}
/********************/
/*    ?????    */
/*     pyyaoer      */
/*   2011.11.26     */
/********************/
int NUM=0;
void num(int,int);              //????
int main()
{
	int p,i,m[21],n[21];
	cin>>p;
	for (i=1;i<=p;i++)         //????p???       
	{
		cin>>m[i]>>n[i]; 
		num(m[i],n[i]);       //????
		cout<<NUM<<endl;
		NUM=0;                //????
	}
	return 0;
}
void num(int m,int n)        //?????
{
	if (m==0||n==1)
		NUM=NUM+1;
	else if (m<n)
		 num(m,n-1);         //m??n???????????
	else
	{
		 num(m,n-1);        //??????????m-n?????n???
		 num(m-n,n);
	}
}
//********************
//**??????	**
//**?????		**
//**???2013.11.28**
//**????2.cpp	**
//********************
int N, M;
int method(int N, int M) // ??????????
{
	if (N == 1 || (N == 0 && M == 0)) // ??1????????????
		return 1; // ??????1
	if (N > M) // ?N > M?????????
		return method(N - 1, M); // ???????????

		/*??????????????????
		  ????????????????1??????*/
		return method(N - 1, M) + method(N, M - N);
}
int main()
{
	int t, i, K;
	cin >> t; // ??????t
	for (i = 0;	i < t; i++) // ??t?
	{
		cin >> M >> N; // ??????M?????N
		K = method(N, M); // ??method?????????????
		cout << K << endl; // ??K
	}
	return 0;
}
const int mov[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};

int m, n, counter;

void dfs(int m, int n, int i) {
	//cout << m << ' ' << n << endl;
	if (n == 0) {
		if (m == 0) {
			++counter;
		}
		return;
	}
	for (; i <= m-n+1; ++i) {
		dfs(m-i, n-1, i);
	}
}

int main() {
	int t, m, n;
	cin >> t;
	while (t--) {
		counter = 0;
		cin >> m >> n;
		dfs(m, n, 0);
		cout << counter << endl;
	}
}
int f(int m,int n)
{
	int k=0;
	if(m==0) k=1;
	if(m==1) k=1;
	if(n==1) k=1;
    if(m<n&&m>1) k=f(m,n-1);
	if(m>=n&&n>1) k=f(m,n-1)+f(m-n,n);
	return k;
}
int main()
{
	int t,i,k,m,n;
    scanf("%d",&t);
	for(i=0;i<t;i++)
	{
		scanf("%d %d",&m,&n);
		k=f(m,n);
		printf("%d\n",k);
	}
	return 0;
}
int fact(int a, int b)
{
    if((a<1) || (b<1)) return 0;  
    if(a==1 || b==1) return 1; 
    if(a<b) return fact(a,a); 
    if(a==b) return fact(a,b-1)+1; 
    return fact(a,b-1)+fact(a-b,b);
}
main()
{
int t,M,N;
scanf("%d",&t);
while(t--)
{
     scanf("%d %d",&M,&N);
   printf("%d\n",fact(M,N)); 
}

}
int f(int m,int n)
{
  if(n==1) return 1;
  if(n>m)        return(f(m,m));
  if(n==m)       return(f(m,m-1)+1);
  if(n<m)        return (f(m,n-1)+f(m-n,n));
  
}

int main()
{
 int f(int m,int n);
 int i,n,M,N;
 scanf("%d",&n); 
 for(i=1;i<=n;i++)
{
  scanf("%d %d",&M,&N);
  f(M,N);
  printf("%d\n",f(M,N));
}

}
//*************************************
//** ???Nov 27, 2013 - ????? **
//** ?????? 1300012719         **
//** ???2013.11.28                **
//*************************************
int WAY2(int x, int y);                      //WAY1,WAY2????x?????y????,??????????????????????
int WAY1(int x, int y)
{
	if (y == 1)
		return 0;
	else if (y == 2)                         //???????1,?????0,??????2?????1,???????x?????y-1????????
		return 1;
	else
		return WAY1(x,y-1) + WAY2(x,y-1);
}
int WAY2(int x, int y)
{
	if (x < y)                               //??????????,?????0,????????1,???????x-y?????y????????
		return 0;
	else if (x == y)
		return 1;
	else
		return WAY1(x-y,y) + WAY2(x-y,y);
}
int main()
{
	int i, n, M, N, K;                       //M,N,K???????????
	cin >> n;                                //??????,????????????????
	for (i = 1; i <= n; i++)
	{
		cin >> M >> N;
		K = WAY1(M,N) + WAY2(M,N);
		cout << K << endl;
	}
	return 0;
}
int f(int m,int n)
{
    int k;
    if(m==0||n==1)
    {k=1;}
    else
    {
        if(m>=n)
        {k=f(m,n-1)+f(m-n,n);}
        else
        {k=f(m,m);}
    }
    return k;
}
main()
{
    int m,n,t,p;
    scanf("%d",&t);
    for(;t!=0;t--)
    {
        scanf("%d %d",&m,&n);
        printf("%d\n",f(m,n));
    }
}
int main()
{
	int f(int x,int y);
	int t,m,n,i,k;
	scanf("%d",&t);
	for(i=0;i<t;i++)
	{
		scanf("%d %d",&m,&n);  //m???????n????
		k=f(m,n);
		printf("%d\n",k);
	}
	return 0;
}

int f(int x,int y)  //x?????y????
{
	int k;
	if(x<=0 || y==0)
		k=0;
	else
	if(x==1 || y==1)
		k=1;
	else
		if(x==y) k=f(x,y-1)+f(x-y,y)+1;
	else
	{
		k=f(x,y-1)+f(x-y,y);
	}
	return k;
}
int put(int ,int);
int main()
{
    int apple,plate,n,sum=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>apple>>plate;
        cout<<put(apple,plate)<<endl;
    }
    return 0;
}

int put(int apple,int plate)
{
   if(plate==1 || apple==1) return 1;
   if(apple<plate) return put(apple,apple);
   if(apple==plate) return put(apple,plate-1)+1;
   return put(apple-plate,plate)+put(apple,plate-1);
}
int f(int m,int n)
{
	int k;
	if(m<n)
    {
		if(m==1) k=1;
		else k=f(m,m);
	}
	if(m>=n)
	{
		if(n==1||n==0) k=1;
		else k=(f(m,(n-1))+f((m-n),n));
	}
	return (k);
    
}
void main()
{
	int n,m,k,i;
	scanf("%d\n",&k);
	for(i=1;i<=k;i++)
	{
		scanf("%d %d\n",&m,&n);
		int y=f(m,n);
		printf("%d\n",y);
	}

}
int main()
{
    int app(int x,int y);
    int s, x, y, i;
    scanf("%d",&s);
    for(i=1;i<=s;i++)
    {
                     scanf("%d%d",&x,&y);
                     printf("%d\n",app(x,y));
    }
    return 0;
}
    
    
    
    
    
int app(int x,int y)
{
    if(x<y&&y!=1)
    {
         return app(x,y-1);
    }
    else if(y==1) 
    {
         return 1;
    }
    else
    {
         return (app(x,y-1)+app(x-y,y));
    }
}
int t,m,n;
int K(int a,int b,int c)
{
	int count=0;
	if (a==n-1&&b<=c) 
		return 1;
	for (int i=b;i<=(c/(n-a));i++)
		count+=K(a+1,i,c-i);
	return count;
}
int main()
{
	cin>>t;
	for(int i=1;i<=t;++i){
		cin>>m>>n;
	cout<<K(0,0,m)<<endl;
	}
	return 0;
}
int max(int a,int b)
{
    if(a<1||b<1)
    return 0;
    if (a==1||b==1)
    return 1;
        if(a<b)
        return max(a,a);
        if
        (a==b) return (max(a,b-1)+1);
        if(a>b)
        return (max(a-b,b)+max(a,b-1));
}
int main ()
{
    int t,a[20],b[20],i,m;
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        scanf("%d %d",&a[i],&b[i]);
    }
     for(i=0;i<t;i++)
    {
        m=max(a[i],b[i]);
        printf("%d\n",m);
    }
}
int digui(int x,int y)

{

       int z;

       if(x==1||x==0)
        z=1;
       else if(y==1) z=1;
       else if(x>=y) z=digui(x-y,y)+digui(x,y-1);
       else z=digui(x,x);
       return z;

}

int main()

{

       int t,n,m;

       scanf("%d",&t);

       while(t--)

       {

              scanf("%d %d",&m,&n);

              printf("%d\n",digui(m,n));

       }

       return 0;

}
int f(int m,int n)
{
	if (m<0||n<0) return (0);
	else if(m==1||n==1||m==0||m==1) return (1);
	else 
		return (f(m-n,n)+f(m,n-1));
}
void main()
{
	int x,i,j;
	scanf("%d",&x);
	int s[100][2];
	for (i=0;i<x;i++)
	{
		scanf("%d",&s[i][0]);
		scanf("%d",&s[i][1]);
	}
	for (j=0;j<x;j++)
	   printf("%d\n",f(s[j][0],s[j][1]));
}
// ?????????
 // ??????
 // ???2010?12?5?
 // ????????


int fang(int m,int n);
int main()
{
	int t,a,b,i,d;                        // ??????????
	cin>>t;
	for (i=1;i<=t;i++)
	{
		cin>>a>>b;
		d=fang(a,b);
		cout<<d<<endl;
		a=0;
		b=0;
		d=0;
	}
	return 0;
}

int fang (int m,int n)
{
	int s;
	if (m==0||n==1)
	return 1;
	else
	{
	if (m<n)
	{
	s=fang(m,m);
	}
	else 
	{
	s=fang(m-n,n)+fang(m,n-1);
	}
	return s;
	}
}
/*
 * ParallelResistance.cpp
 *
 *  Created on: 2011-9-21
 *      Author: 1100012959
 */

int sol(int apple,int plate)//?????????
{
	int solution;//???????
	if(plate==1||apple==0)//??????????1?????0
		solution=1;//??????
	else if(apple>=plate)//???????????
	{
		solution=sol(apple-plate,plate)+sol(apple,plate-1);//????????????????????
	}
	else if(apple<plate) solution=sol(apple,plate-1);//?????????????????
	return solution;
}
int main()
{
	int n,apple,plate,solution;
	cin>>n;
	for(;n>0;n--)//????
	{
		cin>>apple>>plate;
		solution=sol(apple,plate);
		cout<<solution<<endl;
	}
	return 0;
}
int ghl(int p,int q,int r) //r??????? ?q????????????p?????? 
{
   int i,s=0;
   if(r==0 && p!=0) return 0;
   if(p==0) return 1;
   for(i=p;i>=1;i--)
     if(i<=q)
       s+=ghl(p-i,i,r-1);    
    return s;
}
int main()
{
  int m,n,t,sum,i;
  scanf("%d",&t);
  for(i=1;i<=t;i++)
  {
    scanf("%d%d",&m,&n);
    sum=ghl(m,m,n);
    printf("%d\n",sum);
  }
 return 0;    
}
int count(int m,int n)
{
	int y;
	if(m==1||n==1) y=1;
	else if(m>n) y=count(m-n,n)+count(m,n-1);
	else if(m==n) y=1+count(m,n-1);
	else if(m<n) y=count(m,m);
	return y;
}
int main()
{
	int m,n,t,i;
	scanf("%d",&t);
	for(i=1;i<=t;i++)
	{
		scanf("%d %d",&m,&n);
		printf("%d\n",count(m,n));
	}
	return 0;
}
int func(int p,int q)
{
    int t;
    if(p==1||q==1) 
    {
        return 1;
    }
    if(p>q)
    {
        t=func(p,q-1)+func(p-q,q);
    }
    else if(p==q)
    {
        t=func(p,q-1)+1;
    }else t=func(p,p);
    return(t);
}
int main()
{
    int i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        printf("%d\n",func(a,b));
    }
    return 0;
}
int main()
{
	int find(int,int);
	int t,m,n;
	scanf("%d",&t);
	while (t-->0)
	{
		scanf("%d%d",&m,&n);
		printf("%d\n",find(m,n));
	}
	return 0;
}

int find(int m,int n)
{
//	printf("%d %d\n",m,n);
	if (m==1 || m==0) return (1);
	else if (n==1) return (1);
		else
			if (m>=n) return (find(m-n,n)+find(m,n-1));
			else return (find(m,n-1));
}
/*
 * 4.cpp
 *
 *  Created on: 2010-11-30
 *      Author: ???
 *        ??? ???
 */



int k(int m,int n){
	if(n==1)
		return 1;
	if(m>=n)
		return k(m-n,n)+k(m,n-1);
	else
		return k(m,n-1);
}

int main(){
	int m,n,zu;
	cin>>zu;
	for(int i=1;i<=zu;i++){
	    cin>>m>>n;
	    cout<<k(m,n)<<endl;
	}
	return 0;
}
int apple(int a,int b)
{
	int k=0;
	if(a==0||b==1)
		k=1;
    else if(a<b)
	{
		k=apple(a,a);
	}
	else
	{
		k=apple(a,b-1)+apple(a-b,b);
	}
	return(k);
}
int main()
{
	int t,m[2000],n[2000],i;
	scanf("%d",&t);
    for(i=0;i<t;i++)
	{
		scanf("%d%d",&m[i],&n[i]);
	}
	for(i=0;i<t;i++)
	{
		printf("%d\n",apple(m[i],n[i]));
	}
	return 0;
}
int type(int m,int n)
{int c;
	if(m==1||n==1)
c=1;
else if(m==0||n==0)
	c=1;
else if(m<n)
	c=type(m,m);
else 
	c=type(m,n-1)+type(m-n,n);
return(c);}
int main()
{int type(int m,int n);
	int t,M[20],N[20],i;

	scanf("%d",&t);
for(i=0;i<t;i++)
scanf("%d%d",&M[i],&N[i]);
for(i=0;i<t;i++)
printf("%d\n",type(M[i],N[i]));
return 0;
}
int counter=0;
void Divide(int ,int ,int );
int main()
{
  int t,N,M;
  cin>>t;
  for(int i=0;i<t;i++)
  {
  cin>>N>>M;
  counter=0;
  Divide(N,M,N);
  cout<<counter<<endl;
  }

  return 0;
}
void Divide(int n,int m,int s )
{
  if(s>=1)
  {
  for(int i=s;i>=1;i--)
  {   if(n-i==0)
     { 
      counter+=1;
     }
      else if(n-i>0&&m-1>0)
      Divide(n-i,m-1,i);
  }
  }
}
int all(int m,int n)
{
    int empty(int m,int n);
    int noempty(int m,int n);
    int sum;    
    sum=empty(m,n)+noempty(m,n);
    return(sum);
}
int empty(int m,int n)
{
    int s1;
    if(n==1)
    s1=0;
    else
    s1=all(m,n-1);
    return(s1);
    }
int noempty(int m,int n)
{
    int s2;
    if(m-n<0)
    s2=0;
    else if(m-n==0)
    s2=1;
    else 
    s2=all(m-n,n); 
    return(s2);
}
int main()
{
    int m,n,i,t,a[100],b[100];
    scanf("%d",&t);
     for(i=0;i<t;i++)
     scanf("%d%d",&a[i],&b[i]);
     for(i=0;i<t;i++)
     {
                     printf("%d\n",all(a[i],b[i]));
     }
return 0;
}
int apple(int ,int );
int main()
{
	int t,i,m,n,a;
	cin>>t;
	for(i=1;i<=t;i++)
		{
			cin>>m>>n;
			a=apple(m,n);
			cout<<a<<endl;
	}
	return 0;
}
int apple(int m,int n)
{
	int a;
	if(m==1||m==0||n==1)
	{
		a=1;
	}
	else 
		{
			if(m>=n)
	{
		a=apple(m-n,n)+apple(m,n-1);
	}
	if(m<n)
	{
		a=apple(m,n-1);
	}
	}
	return a;
}
int F(int a,int b)
{
    if(a==1||a==0)return 1;
    if(a<0) return 0;
    else if(b==1)return 1;
    else return F(a,b-1)+F(a-b,b);
}    
int main()
{
      int i, t;
      scanf("%d",&t);
      for(i=0;i<t;i++)
      {
              int m,n,k;
              scanf("%d %d",&m,&n);
              k=F(m,n);
              printf("%d\n",k);
      } 
      
}
//********************************
//*?????(15-11) ????? **
//*?????? 1300012991 **
//*???2013.11.29 **
//********************************

int way(int app, int bas); //?????way?????????
int main()
{
	int t, i;
	cin >> t; //????
	for (i = 0; i < t; i++)
	{	
		int app = 0, bas = 0; //app??????bas?????
		cin >> app >> bas;
		cout << way(app, bas) << endl; //??
	}
	return 0;
}

int way(int app, int bas) //?????
{
	int count = 0; //count??????????0

	//???????????????????????????????0????0??????
	if(app == 1 || bas == 1 || app == 0 && bas > 0 || bas == 0 && app > 0)
		count = 1;
	if(app > 1 && bas > 1) //?????????1?????????????????????????
	{
		int ap1 = app - bas;
		int ba1 = bas - 1;
		count = way(app, ba1) + way(ap1, bas);
	}
	return count; //?????
}
int B(int,int);
int main()
{
	int t,m,n;
	cin>>t;
	for(int i=0;i<t;++i)
	{
		cin>>m>>n;
		int sum=0;
		for(int j=1;j<=n;++j)
			sum+=B(m,j);
		cout<<sum<<'\n';
	}
	return 0;
}

int B(int n,int k)
{
	if(k==1||n==k)
		return 1;
	else
	{
		if(k>n) return 0;
		else{
			int result=0;
			for(int l=k;l>0;--l)
				result+=B(n-k,l);
			return result;
		}
	}
}
int c(int m, int n)
{
	int s1, s2, k = m;
	s1 = s2 = 1;
	while (k--)
	{
		s1 *= n--;
		s2 *= m--;
		//cout << s1 << ' ' << s2 << endl;
	}
	return s1 / s2;
}


int f(int m, int n)
{
	if (n == 1)
		return 1;
	//if (m == 0)
		//return 1;
	if (m < n)
	{
		return f(m, n - 1);
	}
		
	return f(m, n - 1) + f(m - n, n);
}

int main()
{
	int t;
	cin >> t;
	//cout << c(5, 3);
	//c(3, 5);

	int m, n;
	while (t--)
	{
		cin >> m >> n;
		cout << f(m, n) << endl;
	}
	return 0;
}
//********************************
//*?????(15-11) ?????   **
//*?????? 1300012934 **
//*???2013.11.28  **
//********************************
int k, l, n;
void put (int p, int q)
{
	int j;
	for (j = p; j <= q; j++)
	{
		l = l - j;
		n--;
		if (n < 0)
		{
			l += j;
			n++;
			break;
		}
		else
		{
			if (l < 0)
			{
				l += j;
				n++;
				break;
			}
			if (l == 0)
			{
				k++;
				l += j;
				n++;
				break;
			}
			if (l > 0)
			{
			    put (j, l);
				l += j;
				n++;
			}
		}
	}

}
int main()
{
	int t, m;
	cin >> t;
	for (int i = 1; i <= t; i++)
	{
		k = 0;
		cin >> m >> n;
		l = m;
		put (1, m);
		cout << k << endl;
	}

	return 0;
}
int f(int x,int y){
	if(x==0)return 1;
	else if((x!=0)&&(y==0))return 0;
	else if((x!=0)&&(y!=0)&&(x>=y))return f(x-y,y)+f(x,y-1);
	else return f(x,y-1);
}
int main(){
	int n,k,i,m;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>k;
		cin>>m;
		cout<<f(k,m)<<endl;
      }
	return 0;
}
int main ( )
{
	int t, M, N, i;
	cin >> t;
	int f(int x, int y);
	for (i = 0;i < t;i++)
	{
		cin >> M >> N;
		cout << f(M, N) <<endl;
	}
	return 0;
}
int f(int x, int y)/*?????*/
{
	int num, m, n;
	if (y == 1 || x == 0)/*????????????????1*/
		return 1;
	else if (y != 1 && x != 0 && x < y )/*?????????,???????*/
		return (f(x, y-1));
	else
	return (f(x, y-1) + f(x-y, y));/*?????????*/
}
int fang(int a,int b)
{
    int m; 
    if(b==1||a==0) m=1;
    else
    {
        if(a>=b) m=fang(a-b,b)+fang(a,b-1);
        if(a<b)  m=fang(a,b-1);
    }
    return m;
}
main()
{
      int i,p,q,a,n;
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
          scanf("%d %d",&p,&q);
          a=fang(p,q);
          printf("%d\n",a);
      }
}
int a=0;
int fang(int m,int n)
{
    if (n==1)
	   a=1;
    if (m==0);
       a=1;
	if ((m<n)&&(n>1))
	   a=fang(m,n-1);
	if ((m>=n)&&(n>1))
       a=fang(m,n-1)+fang(m-n,n);
	//cout<<a;
   return (a);
}
int main()
{
    int t,i;
	cin>>t;
	for (i=0;i<t;i++)
	{
       int m,n;
	   cin>>m>>n;
	   cout<<fang(m,n)<<endl;
	}
    return 0;
}
int f(int m,int n)
{
	int i,s=0;
	for(i=0;i<m;i++)
	{
		if(n>=m-i)
		s=s+f(m-i,n-m+i);
		}
	if(n==0)
	s=1;
	return s;
}
int main()
{
	int m,n,s;
	scanf("%d",&s);
	for(;s>1;s--)
	{
		scanf("%d%d",&m,&n);
		printf("%d\n",f(n,m));
		}
scanf("%d%d",&m,&n);
		printf("%d",f(n,m));
}
int num(int m, int n)
{
 if(m <= 1) return 1;
 if(n == 1) return 1;
 int sum = 0, i;
 for(i = 1; i <= n; i++)
 {
  if(i > m) break;
  sum += num(m - i, i);
 } 
 return sum;
}
int main()
{
 int n, i;
 scanf("%d", &n);
 for(i = 0; i < n; i++)
 {
  int M, N;
  scanf("%d%d", &M, &N);
  int r = num(M, N);
  printf("%d\n", r);
 }
 return 0;
}
int main(){
    int t,m,n,i,j,f[NUM][NUM];
    for(i=1;i<NUM;++i)f[0][i]=1,f[i][0]=0;
    for(i=1;i<NUM;++i)
        for(j=1;j<NUM;++j)
            if(i<j)f[i][j]=f[i][j-1];
            else f[i][j]=f[i-j][j]+f[i][j-1];

    cin>>t;
    while(t--){
        cin>>m>>n;
        cout<<f[m][n]<<endl;
    }
}
int main()
{
	int he(int p,int q);
	int t,m,n;
	int i,sum;
	scanf("%d",&t);
	for(i=0;i<t;i++)
	{
		scanf("%d %d",&m,&n);
		sum=he(m,n);
		printf("%d\n",sum);
	}
	return 0;
}
int he(int p,int q)
{
	int kong(int a,int b);
	int man(int c,int d);
	int h;
	if(q==1) h=1;
	else h=kong(p,q)+man(p,q);
	return h;
}
int kong(int a,int b)
{
	int he(int p,int q);
	int e;
	if(b==1) e=1;
	else 
	{
		e=he(a,b-1);
	}
	return e;
}
int man(int c,int d)
{
	int he(int p,int q);
	int f;
	if(c<d) f=0;
	else if(d==1) f=1;
	else f=he(c-d,d);
	return f;
}
int kk(int m,int n){
    if(m==0)
    return 1;
    else {
    if(n==1)
    return 1;
    else {
   if(m<n)
   return kk(m,m);
   if(m>=n)
   return kk(m,n-1)+kk(m-n,n);
      }
      }
      }
int main(){
    int m,n,t;
    cin>>t;
    int i,aa[t+1];
    for(i=1;i<=t;i++){
     cin>>m>>n;
     aa[i]=kk(m,n);
     }
    for(i=1;i<=t;i++)
    cout<<aa[i]<<endl;
    
    return 0;
}
int devide(int m,int n)
{   
    int full,empty,sum;
    if (n==2)
    return 1+m/2;
    else 
      {
    empty=devide(m,n-1);
    if (m<n)
    full=0;
    else
    full=devide(m-n,n);
    sum=full+empty;
    return sum;
      } 
}




main()
{
      int N,M,n,c,t,k;
      scanf("%d",&n);
      for(t=1;t<=n;t++)
      {
      scanf("%d %d",&M,&N);
      if (N==1)
      printf("1");
      else
      printf("%d",devide(M,N)); 
      printf("\n"); 
      }
}
int apple(int m,int n,int j); 
int main(void) 
{ 
	int t,j,n,m,s; 
    scanf("%d",&t);
	for(j=0;j<t;j++) 
	{
		scanf("%d%d",&m,&n); 
        if(n>m) n=m; 
        s=apple(m,n,0); 
        printf("%d\n",s); 
	}
	return 0;
}

int apple(int m,int n,int j) 
{
	int i,s=0; 
	if(n==1) return m>=j; 
    for(i=j;i<m;i++) s+=apple(m-i,n-1,i); 
    return s; 
}
//********************************
//*????????    **
//*?????? 1300012887 **
//*???2013.11.27 **
//********************************
int count(int M, int N)  //??????????
{
	if (M == 1 || N == 1 || N == 0)  //??????????1??????0
		return 1;  //??1?
	if (M < N)  //??????????
		return count(M, M);  //??????????????????
	return (count(M, N-1) + count(M-N, N));  //????????????????????
}
int main()  //?????
{
	int t, i, a, n, m;
	cin >> t;  //????????
	cin.get();
	for (i = 0; i < t; i++)
	{
		cin >> m >> n;  //????????
		a = count (m, n);
		cout << a << endl;  //??????
	}
	return 0;
}
int main()
{int n,m,sum,a,b,i;
int f(int x,int y);
scanf("%d",&a);
for (i=0;i<a;i++)
{
scanf("%d %d",&m,&n );
sum=f(m,n);
printf("%d\n",sum);}
	return 0;
}

int f(int m,int n)

{if (m==0||n==1) return 1;
 if(n>m)   return f(m,m);
 if (n==1) return 1;
 else if (n!=1) return (f(m,n-1)+f(m-n,n)); 


}
// ?????.cpp : ??????????????
//



int main()
{//declaration
	short apple(int m,int n);
	int t,m,n,k[20];
	int i;
//input process
	scanf("%d",&t);
	for(i=0;i<=t-1;i++)
	{
		scanf("%d%d",&m,&n);
		k[i]=apple(m,n);
	
	}
//output
	for(i=0;i<=t-1;i++)printf("%d\n",k[i]);

	return 0;
}

short apple(int m,int n)
{
	short res=0;
	if(m<=1||n<=1)res=1;
	else
	{ 
		if(m>=n)res=apple(m-n,n);
		res=res+apple(m,n-1);
	}
	return res;

}