#include<stdio.h> //(m+n)!*(m+1-n)/(m+1) 代表:m个50块, n个100块,, 不同的人排列,
int main()
{
int a[1000];
int i, j, n, m, s, tot, x=0, f, e, b;
while(scanf("%d%d", &m, &n)!=EOF && m!=0)
{
memset(a,0,sizeof(a));
s = 0;
tot = 0;
x++;
printf("Test #%d:\n", x);
a[0]=1;
for(i=2; i<=n+m; i++) // 阶乘
{
for(j=0; j<1000; j++)
{
s = a[j]*i+s;
a[j] = s%10;
s = s/10;
}
}
tot = m+1-n;
for(j=0,s=0; j<1000; j++) // 数组乘上一个数字
{
s = a[j]*tot+s;
a[j] = s%10;
s = s/10;
}
for(j=1000-1;j>=0;j--)// 从后面判断数组存数的大小
{
if(a[j]!=0)
break;
}
f = m+1;
for(i=j,b=s=0; i>=0; i--) // 非常重要:数组存数, 然后用数组a[i] 除 数字f 。{
{
s = s*10+a[i];
if(b==0)
{
if(s>f)
{
printf("%d", s/f);
b = 1;
}
}
else
printf("%d", s/f);
s = s%f;
}// }
printf("\n");
}
#include<stdio.h>
int tot;
int s;
void chang(int n, int m, int s1, int s2, int s3)
{
int i, j, s;
if(s3 == n+m)
tot++;
else
{
if(s1>=s2)
{
if(s1<n)
chang(n, m, s1+1, s2, s3+1);
if(s2<m)
chang(n, m, s1, s2+1, s3+1);
}
}
}
int main()
{
int i, n, j, m, x=0;
while(scanf("%d%d", &n, &m)!=EOF && n!=0)
{
s = 0;
tot = 0;
x++;
if(n>=m)
{
chang(n, m, 0, 0, 0);
for(i=2; i<=n; i++)
{
if(i<=m)
tot = tot*i*i;
else
tot = tot*i;
}
}
printf("Test #%d:\n%d\n", x, tot);
}
}
*/
int main()
{
int a[1000];
int i, j, n, m, s, tot, x=0, f, e, b;
while(scanf("%d%d", &m, &n)!=EOF && m!=0)
{
memset(a,0,sizeof(a));
s = 0;
tot = 0;
x++;
printf("Test #%d:\n", x);
a[0]=1;
for(i=2; i<=n+m; i++) // 阶乘
{
for(j=0; j<1000; j++)
{
s = a[j]*i+s;
a[j] = s%10;
s = s/10;
}
}
tot = m+1-n;
for(j=0,s=0; j<1000; j++) // 数组乘上一个数字
{
s = a[j]*tot+s;
a[j] = s%10;
s = s/10;
}
for(j=1000-1;j>=0;j--)// 从后面判断数组存数的大小
{
if(a[j]!=0)
break;
}
f = m+1;
for(i=j,b=s=0; i>=0; i--) // 非常重要:数组存数, 然后用数组a[i] 除 数字f 。{
{
s = s*10+a[i];
if(b==0)
{
if(s>f)
{
printf("%d", s/f);
b = 1;
}
}
else
printf("%d", s/f);
s = s%f;
}// }
printf("\n");
}
}
下面是用的递归, 但不能通过。
/*#include<stdio.h>
int tot;
int s;
void chang(int n, int m, int s1, int s2, int s3)
{
int i, j, s;
if(s3 == n+m)
tot++;
else
{
if(s1>=s2)
{
if(s1<n)
chang(n, m, s1+1, s2, s3+1);
if(s2<m)
chang(n, m, s1, s2+1, s3+1);
}
}
}
int main()
{
int i, n, j, m, x=0;
while(scanf("%d%d", &n, &m)!=EOF && n!=0)
{
s = 0;
tot = 0;
x++;
if(n>=m)
{
chang(n, m, 0, 0, 0);
for(i=2; i<=n; i++)
{
if(i<=m)
tot = tot*i*i;
else
tot = tot*i;
}
}
printf("Test #%d:\n%d\n", x, tot);
}
}
*/