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的更多相关文章
随机推荐
- springmvc 全局的异常拦截处理 @ControllerAdvice注解 @ExceptionHandler
第一步: Dispatcher前端控制器的源码中 默认的 private boolean throwExceptionIfNoHandlerFound = false;说明如果没有找到匹配的执行器,不 ...
- MockPlus的使用方法简介
不废话直接上图,不明白的留言.
- SelectedItems的用法讲解
在做俄罗斯方块的时候写了下面一段代码: private void listView1_SelectedIndexChanged(object sender, EventArgs e) ...
- sheepdog
- SharePoint 2013 - User Custom Action
1. User Custom Action包含Ribbon和ECB,以及Site Action菜单等,参考此处: 2. 系统默认ECB的Class为: ms-core-menu-box --> ...
- mysql导入导出csv
LOAD DATA local INFILE '/tmp/stb.csv' INTO TABLE stb FIELDS TERMINATED BY ',' enclosed by '"' l ...
- shell中和RDA中的alert日志中文乱码
客户端字符集无法识别中文,只能下载到本机使用nodepad++查看
- Android SDK Manager 如何下载?
修改 "C:\Windows\System32\driver\etc\hosts" 文件,添加以下两行 203.208.40.111 dl-ssl.google.com 203.2 ...
- April 1 2017 Week 13 Saturday
There is more to life than increasing its speed. 生活不仅仅是匆匆赶路. Get a life, a real life, not a manic pu ...
- Python之List和Tuple类型(入门3)
转载请标明出处: http://www.cnblogs.com/why168888/p/6407682.html 本文出自:[Edwin博客园] Python之List和Tuple类型 1. Pyth ...