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