In how many ways can you choose k elements out of n elements, not taking order into account?
Write a program to compute this number.

Input

The input will contain one or more test cases.

Each test case consists of one line containing two integers n (n>=1) and k (0<=k<=n).

Input is terminated by two zeroes for n and k.

Output

For each test case, print one line containing the required number. This number will always fit into an integer, i.e. it will be less than 2
31.

Warning: Don't underestimate the problem. The result will fit into an integer - but if all intermediate results arising during the computation will also fit into an integer depends on your algorithm. The test cases will go to the limit.

Sample Input

4 2
10 5
49 6
0 0

Sample Output

6
252
13983816

求C(n,k),模板题
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
#define ll long long
#define M 105 ll n,k; int main()
{
ll i,j;
while(cin>>n>>k)
{
if(n==0&&k==0)
break;
if(k==n)
{
cout<<1<<endl;
continue;
} if(n-k<k)
k=n-k;
ll ans=1;
for(i=1;i<=k;i++)
{
ans=ans*(n-i+1)/i;
}
cout<<ans<<endl;
}
}

  

最新文章

  1. java-汉字转换拼音-pinyin4j.jar
  2. oracle sqlplus 连接不正常
  3. 第三次作业——K米评测
  4. css平时写的时候注意的
  5. [主席树]HDOJ2665 &amp;&amp; POJ2104 &amp;&amp; POJ2761
  6. 使用GDI+轻松创建缩略图
  7. 解决window7 x64位Anaconda启动报错:AttributeError: &#39;_NamespacePath&#39; object has no attribute &#39;sort&#39;
  8. RabbitMQ消息队列(六):使用主题进行消息分发
  9. SpringCloud2.0入门4-springboot-admin监控
  10. JDK动态代理(1)-----------new 对象的方式
  11. C++ 成员初始化列表
  12. H5C301
  13. Linux下的搜索查找命令的详解(which)
  14. 百度AI搜索引擎
  15. 一些hue的参考网址
  16. hdu 4549 M斐波拉契 (矩阵快速幂 + 费马小定理)
  17. shell文件的编写
  18. 【正则表达式】使用正则表达式的group,查找出String中的参数值
  19. scala case类
  20. 微信授权获取code(微信支付)

热门文章

  1. Docker 创建镜像、修改、上传镜像
  2. Maven之依赖关系
  3. canvas-菜鸟版画布时钟
  4. 【Eclipse】在Eclipse上安装Spket
  5. 使用gulp解决外部编辑器修改Eclipse文件延迟刷新
  6. spring----spring中的注解@service等的作用
  7. redis 笔记(二)
  8. 在centos7中安装redis,并通过node.js操作redis
  9. pl/sql中的一种链接数据库方式
  10. oracle 12c使用dblink克隆pdb