分类:
2010-08-16 15:40:40
//个人认为自己的思路不错
#include
#include
#include
#include
using namespace std;
int gcd(int a,int b)
{
if(a return gcd(b,a);
else
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
}
void treat(int *a,int *b)
{
int tmp=gcd(*a,*b);
*a=*a/tmp;
*b=*b/tmp;
}
int main()
{
int m,n,n_bak;
while(1)
{
scanf("%d%d",&m,&n);
if(m==0&&n==0)
break;
n_bak=n;
if(n>m-n)
n=m-n;
list
list
for(int i=1;i<=n;++i)
{
upm.push_back(m-n+i);
downn.push_back(i);
}
while(!downn.empty())
{
int tmp=*downn.begin();
while(tmp!=1)
{
int tmp_upm=*upm.begin();
upm.pop_front();
treat(&tmp,&tmp_upm);
if(tmp_upm!=1)
upm.push_back(tmp_upm);
}
downn.pop_front();
}
int ans=1;
while(!upm.empty())
{
ans*=*upm.begin();
upm.pop_front();
}
printf("%d things taken %d at a time is %d exactly.\n",m,n_bak,ans);
}
return 0;
}