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. Vue内置组件[回顾]

    1.动态组件 在某些场景,往往需要我们动态切换页面部分区域的视图,这个时候内置组件component就显得尤为重要. component接收一个名为is的属性,is的值应为父组件中注册过的组件的名称, ...

  2. 前端开发CSS3——使用方式和选择器

    CSS是Cascading Style Sheets(层叠样式表)的简写,用于修饰文档的语言,可以修饰HTML.XML.SVN.每个语言都有每个语法的规则:CSS声明.CSS声明块.CSS选择器.CS ...

  3. 谈谈<? extends T> 和<? super T>理解

    项目中遇到<? extends T> 和<? super T> 这两者,来说说自己的理解.首先我们先了解什么是泛型 什么是泛型 泛型是在编译阶段一种防止错误对象输入的机制.编译 ...

  4. ElasticSearch最全分词器比较及使用方法

    介绍:ElasticSearch 是一个基于 Lucene 的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于 RESTful web 接口.Elasticsearch 是用 Java 开 ...

  5. composer基本操作详解

    原文转自微信公众号:qq1005349393 Composer介绍 Composer 是 PHP 的一个包依赖管理工具.我们可以在项目中声明所依赖的外部工具库,Composer 会帮你安装这些依赖的库 ...

  6. js处理日历

    我们在做自动化的时候可能会遇到选择日期这种情况 这个时候我们可能就会想到直接定位不就可以了,为啥还要使用js这种东西呢? 首先,我们想一下定位:定位不仅麻烦而且还不稳定,所以这种方式我是直接就弃用了 ...

  7. 04.UTXO:未使用的交易输出,比特币核心概念之一

    在比特币系统上其实并不存在“账户”,而只有“地址”.只要你愿意,你就可以在比特币区块链上开设无限多个钱包地址,你拥有的比特币数量是你所有的钱包地址中比特币的总和.比特币系统并不会帮你把这些地址汇总起来 ...

  8. Qt工程管理

    Qt Creator工程管理Qt Creator以工程项目的方式对源码进行管理一个Qt Creator工程包含不同类型的文件 .pro项目描述文件.pro.user用户配置描述文件 //由Qt Cre ...

  9. 201871010106-丁宣元 《面向对象程序设计(java)》第八周学习总结

    201871010106-丁宣元 <面向对象程序设计(java)>第八周学习总结 正文开头: 项目 内容 这个作业属于哪个课程 https://home.cnblogs.com/u/nwn ...

  10. MySQL数据库 存储引擎,创建表完整的语法,字段类型,约束条件

    1.存储引擎 - 存储引擎是用于根据不同的机制处理不同的数据. - 查看mysql中所有引擎: - show engines; - myisam: 5.5以前老的版本使用的存储引擎 - blackho ...