Binomial Showdown
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 22692   Accepted: 6925

Description

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 231.

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

题意:输入n,k求C(n,k)。

挺无聊的一题,因为答案在2^32内,直接开long long 然后暴力就行了。

AC code:

#include<cstdio>
using namespace std;
typedef long long int64;
int64 C(int64 n,int64 k)
{
int64 a=,b=;
for(int i=;i<=k;i++)
{
a*=(n+-i);
b*=i;
if(!(a%b)){
a/=b;
b=;
}
}
return a/b;
}
int main()
{
//freopen("input.txt","r",stdin);
int64 n,k;
while(~scanf("%lld%lld",&n,&k)&&n+k)
{
if(k>n/) k=n-k;
printf("%lld\n",C(n,k));
}
}

POJ 2249 暴力求组合数的更多相关文章

  1. POJ 1306 暴力求组合数

    Combinations Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11049   Accepted: 5013 Des ...

  2. poj 3100 (zoj 2818)||ZOJ 2829 ||ZOJ 1938 (poj 2249)

    水题三题: 1.给你B和N,求个整数A使得A^n最接近B 2. 输出第N个能被3或者5整除的数 3.给你整数n和k,让你求组合数c(n,k) 1.poj 3100 (zoj 2818) Root of ...

  3. lucas求组合数C(n,k)%p

    Saving Beans http://acm.hdu.edu.cn/showproblem.php?pid=3037 #include<cstdio> typedef __int64 L ...

  4. URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理

    URAL 1994 The Emperor's plan 求组合数 大数用log #include<functional> #include<algorithm> #inclu ...

  5. POJ 2182/暴力/BIT/线段树

    POJ 2182 暴力 /* 题意: 一个带有权值[1,n]的序列,给出每个数的前面比该数小的数的个数,当然比一个数前面比第一个数小的个数是0,省略不写,求真正的序列.(拗口) 首先想到的是从前到后暴 ...

  6. N!分解质因子p的个数_快速求组合数C(n,m)

    int f(int n,int p) { ) ; return f(n/p,p) + n/p; } https://www.xuebuyuan.com/2867209.html 求组合数C(n,m)( ...

  7. 求组合数、求逆元、求阶乘 O(n)

    在O(n)的时间内求组合数.求逆元.求阶乘.·.· #include <iostream> #include <cstdio> #define ll long long ;// ...

  8. HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解

    题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...

  9. hdu 2519 求组合数

    求组合数 如果求C5 3 就是5*4*3/3*2*1 也就是(5/3)*(4/2)*(3/1) Sample Input5 //T3 2 //C3 25 34 43 68 0 Sample Outpu ...

随机推荐

  1. 如何down掉IB交换机口

    服务器上找到需down的网络:ip a 通过ib命令iblinkinfo找到对应交换机以及在ib交换机上对应端口号 登录IB交换机,并通过命令:config进入配置模式 通过命令:port进入端口配置 ...

  2. Mysql使用ReplicationDriver驱动实现读写分离

    数据库的主从复制环境已经配好,该要解决系统如何实现读写分离功能了.Mysql的jdbc驱动提供了一种实现ReplicationDriver. 1 数据库地址的两种写法 参考:https://dev.m ...

  3. Linux下实现不活动用户登录超时后自动登出

    方法一:通过修改.bashrc或.bash_profile文件来实现  通过修改home目录下的.bashrc或.bash_profile文件来实现.这两个文件选择其中一个在末尾加入如下一行,具体操作 ...

  4. 基于Proxy的小程序状态管理

    摘要: 小程序状态管理. 作者:wwayne 原文:基于Proxy的小程序状态管理 Fundebug经授权转载,版权归原作者所有. 微信小程序的市场在进一步的扩大,而背后的技术社区仍在摸索着最好的实践 ...

  5. Docker下载镜像太慢问题

    我在linux上安装了Docker,docker pull 了一个nginx镜像,真他妈是太慢了用了1-2个小时才下载完成. 在网上找到了优化方法,那真是速度一下就起飞了,其实只要配置一下拉取的doc ...

  6. leetcode - 链表两两元素交换 + 判断链表有无环

    链表两两元素交换 给定一个链表,两两交换其中相邻的节点,并返回交换后的链表. 你不能只是单纯的改变节点内部的值,而是需要实际的进行节点交换. 示例: 给定 1->2->3->4, 你 ...

  7. sql developer 17002报错无法连接

    问题登场: 使用sql developer 登录oracle 时报错,错误码17002 解决办法: 右键,点击properties 属性,检查每一项配置,发现ip 是之前的ip,更改为database ...

  8. SpringBoot使用Swagger2构建API文档

    后端开发中经常需要对移动客户端提供RESTful API接口,在后期版本快速迭代的过程中,修改接口实现的时候都必须同步修改接口文档,而文档与代码又处于两个不同的媒介,除非有严格的管理机制,不然很容易导 ...

  9. 201871010133-赵永军《面向对象程序设计(java)》第七周学习总结

    201871010133-赵永军<面向对象程序设计(java)>第七周学习总结 项目 内容 这个作业属于哪个课程 https://www.cnblogs.com/nwnu-daizh/ 这 ...

  10. CF1245 A. Good ol' Numbers Coloring(java与gcd)

    题意:给定数字A和数字B,问是否满足gcd(A,B)==1. 思路:可以直接写函数gcd.也可以用大数自带的gcd功能. 代码1: /* @author nimphy @create 2019-11- ...