#include<cstdio>
#include<algorithm>
using namespace std;
double permutation(long int n,long int r)
{
int i,k;
double num;
if(r==0)
return 1;
k=min(r,n-r);
num=1;
for(i=k;i>=1;i--)
{
num=num*(n-i+1);
num=num/i;
}
return num;
}
int main()
{
long int n,r;
double g;
while(scanf("%ld%ld",&n,&r)==2)
{
if(n==0&&r==0)
break;
g=permutation(n,r);
printf("%ld things taken %ld at a time is %.0lf exactly.\n",n,r,g);
}
return 0;
}
#include<algorithm>
using namespace std;
double permutation(long int n,long int r)
{
int i,k;
double num;
if(r==0)
return 1;
k=min(r,n-r);
num=1;
for(i=k;i>=1;i--)
{
num=num*(n-i+1);
num=num/i;
}
return num;
}
int main()
{
long int n,r;
double g;
while(scanf("%ld%ld",&n,&r)==2)
{
if(n==0&&r==0)
break;
g=permutation(n,r);
printf("%ld things taken %ld at a time is %.0lf exactly.\n",n,r,g);
}
return 0;
}
No comments:
Post a Comment