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的更多相关文章
随机推荐
- Java内部类详解 2
Java内部类详解 说起内部类这个词,想必很多人都不陌生,但是又会觉得不熟悉.原因是平时编写代码时可能用到的场景不多,用得最多的是在有事件监听的情况下,并且即使用到也很少去总结内部类的用法.今天我们就 ...
- vim 安装vundle 之curl
百度出来的博客文章,配置curl.cmd 的内容win7 x64 好像有误 贴下正确的 @rem Do not use "echo off" to not affect any c ...
- OLEDB事务
学过数据的人一般都知道事务的重要性,事务是一种对数据源的一系列更新进行分组或者批处理以便当所有更新都成功时同时提交更新,或者任意一个更新失败时进行回滚将数据库中的数据回滚到执行批处理中的所有操作之前的 ...
- scss-@else if指令
@else if语句用来与@if指令一起使用.当 @if 语句失败时,则 @else if 语句测试,如果它们也无法测试满足时再 @else 执行. 语法: @if expression { // C ...
- link 和 import 导入外部样式的区别
差别一:link 属于 XHTML 标签,而 @import 完全是 CSS 提供的 一种方式.link标签除了可以加载 CSS 外,还可以做很多事情,比如定义 RSS ,定义 rel 链接属性等. ...
- Html5的map在实际使用中遇到的问题及解决方案
前言:百度了一下html map,嗯嗯,介绍的挺详细的,如果是初学者,直接看他们的教程,挺好的,就不用我再多说了. 不过我发现一个问题,就是都是介绍map有什么属性怎么用的,这明显就是照搬文档自己再改 ...
- Python tqdm show progress bar
tqdm can help to show a smart progress bar, and it is very easy to use, just wrap any iterable with ...
- 关于String s = new String("xyz");创建了几个字符串对象?的问题
引用自这位朋友:http://blog.sina.com.cn/s/blog_6a6b14100100zn6r.html 首先让我们了解几个概念: 栈:由JVM分配区域,用于保存线程执行的动作和数据引 ...
- VBA注意事项
以下是项目过程中遇到的坑,可能有些说明的部分不一定严谨,仅供参考 1.最好保存成 [*.xlsm]文件 2.注意 VBA 的参数类型,使用的参数如果未声明直接使用的话会出现类型不匹配的错误 3.代码写 ...
- nginx配置+uwsgi+负载均衡配置
nginx静态文件配置 location /static{ alias /var/www/myApp/static; } sudo mkdir -vp /var/www/myApp/static/ s ...