poj_1306_Combinations
GIVEN: 5 <= N <= 100; 5 <= M <= 100; M <= N
Compute the EXACT value of: C = N! / (N-M)!M!
You may assume that the final value of C will fit in a 32-bit Pascal LongInt or a C long. For the record, the exact value of 100! is:
93,326,215,443,944,152,681,699,238,856,266,700,490,715,968,264,381,621, 468,592,963,895,217,599,993,229,915,608,941,463,976,156,518,286,253, 697,920,827,223,758,251,185,210,916,864,000,000,000,000,000,000,000,000
Input
Output
N things taken M at a time is C exactly.
Sample Input
100 6
20 5
18 6
0 0
Sample Output
100 things taken 6 at a time is 1192052400 exactly.
20 things taken 5 at a time is 15504 exactly.
18 things taken 6 at a time is 18564 exactly.
#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<<n<<" things taken "<<k<<" at a time is "<<1<<" exactly."<<endl;
continue;
}
cout<<n<<" things taken "<<k<<" at a time is ";
if(n-k<k)
k=n-k;
ll ans=1;
for(i=1;i<=k;i++)
{
ans=ans*(n-i+1)/i;
}
cout<<ans<<" exactly."<<endl;
}
}
poj_1306_Combinations的更多相关文章
随机推荐
- 利用ajax短轮询+php与服务器交互制作简易即时聊天网站
主流的Web端即时通讯方案大致有4种:传统Ajax短轮询.Comet技术.WebSocket技术.SSE(Server-sent Events). 本文主要介绍ajax短轮询的简易实现方式. 看懂此文 ...
- Resharper 的快捷键
编辑 Ctrl + Space 代码完成 Ctrl + Shift + Space代码完成 Ctrl + Alt + Space代码完成 Ctrl + P 显示参数信息 Alt + Inser ...
- CSS垂直居中的四种方法
写在前面的话 最近在Stack Overflow上看到 一个不错的回答 ,以下是我对其的总结,分享给大家. 垂直居中的四种方法 ①基础的方法 设置父元素的line-height等于height,这种方 ...
- 用JQ帮你实现动画导航 手风琴是导航与下拉导航
1.手风琴式导航,既可以适用于移动端也可使用与PC端 <!DOCTYPE html> <html> <head> <meta charset="UT ...
- 使用Gulp压缩HTML和CSS
---恢复内容开始--- 今天我么继续压缩,但是今天的压缩和之前的不同了!可以说是第二种方法吧! 今天用Gulp来压缩HTML和CSS! 1.首先我们先来安装GUlp:先安装全局gulp 2.然后是开 ...
- Angular js 过滤器 笔记(转自菜鸟教程)
1.uppercase,lowercase 大小写转换 {{ "lower cap string" | uppercase }} // 结果:LOWER CAP STRING {{ ...
- RAC常用日志总结
12C RAC:ocssd启动失败log目录:/u01/app/grid/diag/crs/host02/crs/trace/alert.log
- 查询python的安装路径
参考链接: https://blog.csdn.net/orangleliu/article/details/44907221 (tf_14) novak@novak-ZBook15G2:~$ pyt ...
- 作为软件技术人员建立自己的git账户并保存资料的重要性
日常生活中,当修改并保存了一个文件,所得到的就是此文件的最新版本,假若今后因某一问题需要用到原来文件,可是很多情况下,这种修改是不可逆的.你修改完之后,无法回到你修改前的样子.为了避免这种情况,有的人 ...
- OC static 和函数
#include <stdio.h> // 定义一个one函数 // 完整地定义一个外部函数需要extern关键字 //extern void one() { // printf(&quo ...