POJ 2249 暴力求组合数
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 22692 | Accepted: 6925 |
Description
Write a program to compute this number.
Input
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
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 暴力求组合数的更多相关文章
- POJ 1306 暴力求组合数
Combinations Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 11049 Accepted: 5013 Des ...
- 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 ...
- lucas求组合数C(n,k)%p
Saving Beans http://acm.hdu.edu.cn/showproblem.php?pid=3037 #include<cstdio> typedef __int64 L ...
- URAL 1994 The Emperor's plan 求组合数 大数用log+exp处理
URAL 1994 The Emperor's plan 求组合数 大数用log #include<functional> #include<algorithm> #inclu ...
- POJ 2182/暴力/BIT/线段树
POJ 2182 暴力 /* 题意: 一个带有权值[1,n]的序列,给出每个数的前面比该数小的数的个数,当然比一个数前面比第一个数小的个数是0,省略不写,求真正的序列.(拗口) 首先想到的是从前到后暴 ...
- 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)( ...
- 求组合数、求逆元、求阶乘 O(n)
在O(n)的时间内求组合数.求逆元.求阶乘.·.· #include <iostream> #include <cstdio> #define ll long long ;// ...
- HDU 5852 Intersection is not allowed!(LGV定理行列式求组合数)题解
题意:有K个棋子在一个大小为N×N的棋盘.一开始,它们都在棋盘的顶端,它们起始的位置是 (1,a1),(1,a2),...,(1,ak) ,它们的目的地是 (n,b1),(n,b2),...,(n,b ...
- 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 ...
随机推荐
- c# .NET Framework 版本确定
关于.NET Framework 版本信息这里做个介绍: 1. 编译时,工程的目标的 .NET Framework 版本 同样的代码,我先选择.net 4.0,就发现有语法错误,原因是4.0版本还没提 ...
- SpringCloud框架
最近一直在针对SpringCloud框架做项目,从中踩了不少的坑,也渐渐梳理出了一些内容,由于SpringCloud作为一个全家桶,其中东西太多,所以这时候就要有所取舍,这里就想把自己比较常用组件及架 ...
- Java自学-集合框架 遍历
遍历ArrayList的三种方法 步骤 1 : 用for循环遍历 通过前面的学习,知道了可以用size()和get()分别得到大小,和获取指定位置的元素,结合for循环就可以遍历出ArrayList的 ...
- Flask补充--threading.local对象
目录 Local 局部变量 全局变量 使用threading.local() 自定义threading.local 函数版 面向对象版 通过setattr和getattr实现 每个对象有自己的存储空间 ...
- 一句DELETE引发的加班(Mysql 恢复Delete删除的数据)
本机用的Navicat连mysql测试DB又连了正式DB,因为本地与正式要频繁操作所以都打开了很多查询,本来要DELETE删除测试DB的数据,没看清在正式环境执行了.共删除了325条数据,然后在网上找 ...
- CSS颜色、单位、文本样式
一.CSS颜色:关键字 red16进制的6位 #ffffff16进制的3位 #fffrgb(0,255,100) 取值范围:0~255 (r:red.g:green.b:blue)rgba(0,255 ...
- 二、HDFS(架构、读写、NN)
一.HDFS定义 HDFS (Hadooop Distributed File System),它是一个文件系统,用于存储文件,通过目录树来定位文件:其次,它是分布式的,由很多服务器联合走来实现其功能 ...
- 软件设计师【软件工程:软件开发模型、XP极限编程十二最佳实践】
一.软件开发模型 二.XP极限编程十二最佳实践
- flask上下文管理之threading.local
Flask之上下文管理 知识储备之问题情境: request中的参数: 单进程单线程 单进程多线程-->reqeust 会因为多个请求,数据发生错乱.--->可以基于threading.l ...
- Linux下对input设备调用ioctl时指定EVIOCGBIT选项时的缓冲区该多大【转】
转自:https://blog.csdn.net/imred/article/details/82669990 版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出 ...