Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7499 | Accepted: 3509 |
Description
Input
Output
Sample Input
100 6 20 5 18 6 0 0
Sample Output
100 things taken 6 at a time is 1192052400 exactly. 20 things taken 5 at a time is 15504 exactly. 18 things taken 6 at a time is 18564 exactly.
Source
#include<stdio.h> int a[120]; int main() { __int64 n,m,i,j,sum=1,num; while(scanf("%I64d %I64d",&n,&m)) { if(n==0&&m==0)break; for(i=1;i<=110;i++) a[i]=0; sum=1; for(i=n-m+1;i<=n;i++) { num=i; for(j=2;j<=m;j++) { if(a[j]==1)continue; if(num%j==0){num/=j;a[j]=1;} } sum*=num; } for(j=2;j<=m;j++) { if(a[j]==0)sum/=j; } printf("%I64d things taken %I64d at a time is %I64d exactly.\n",n,m,sum); } }
#include<stdio.h> int main() { int n,m,i; double sum1=1,sum2=1; while(scanf("%d %d",&n,&m)!=EOF) { if(n==0&&m==0)break; sum1=1; sum2=1; for(i=n-m+1;i<=n;i++) sum1*=double(i); for(i=1;i<=m;i++) sum2*=double(i); printf("%d things taken %d at a time is %.0lf exactly.\n",n,m,sum1/sum2); } }
#include<stdio.h> __int64 a[110][110]; int main() { int i,j; for(i=0;i<=101;i++) a[i][0]=1; for(i=1;i<=101;i++) a[i][i]=1; for(i=2;i<=101;i++) for(j=1;j<i;j++) { a[i][j]=a[i-1][j]+a[i-1][j-1]; } while(scanf("%d %d",&i,&j)!=EOF) { if(i==0&&j==0)break; printf("%d things taken %d at a time is %I64d exactly.\n",i,j,a[i][j]); } }