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 ...
随机推荐
- Delphi - 操作Excel数据公式的实现
procedure TF_SMP_FT_NEW.RzBitBtn_StartToChangeClick(Sender: TObject); var i, j, ni, nj, iRows, iCol, ...
- 纯C语言实现循环双向链表创建,插入和删除
#include <stdio.h> #include <stdlib.h> typedef int ElemType; typedef struct DLNode{ Elem ...
- mockjs 在项目中vue项目中使用
一.为什么要使用mockjs 总结起来就是在后端接口没有开发完成之前,前端可以用已有的接口文档,在真实的请求上拦截ajax,并根据mockjs的mock数据的规则,模拟真实接口返回的数据,并将随机的模 ...
- SQL之CASE WHEN用法详解
原文链接:https://blog.csdn.net/rongtaoup/article/details/82183743 原文链接:https://www.cnblogs.com/zhuyeshen ...
- 四.Windows基础
系统目录 Windows Program files 用户 Perflogs:是Windows7的日志信息,如磁盘扫描错误信息,删掉可以,但不建议删,删掉反而降低系统速度,perflogs是系统自动生 ...
- Jenkins+gradle+git部署
感谢博友分享,这边记录下https://blog.csdn.net/jiankeufo/article/details/78228334 我的密码7789cc2b62114e9da9fb78b0aa3 ...
- OL7.7安装Oracle 11.2.0.4
安装环境准备工具 yum –y install oracle-rdbms-server-11gR2-preinstall 创建目录 mkdir -p /u01/app/oracle/product/1 ...
- 互联网渗透测试之Wireshark的高级应用
互联网渗透测试之Wireshark的高级应用 1.1说明 在本节将介绍Wireshark的一些高级特性 1.2. "Follow TCP Stream" 如果你处理TCP协议,想要 ...
- Ubuntu启动器快捷方式文件解析
快捷方式名称 app_name.desktop 路径: /usr/share/applications/app_name.desktop # 简洁快捷方式格式 [Desktop Entry] Name ...
- vs解决方案文件出错
问题描述: 电脑死机,重启电脑后打开解决方案,提示“选择的文件不是有效的解决方案文件” 解决方案: 1. 先用记事本打开这个解决方案查看下,发现其中内容变成空白了? 2. 打开项目中的xxxx.vcx ...