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的更多相关文章
随机推荐
- 转:HTML中让图片滚动的<marquee>标签的使用方法
实例: <marquee id="affiche" align="left" behavior="scroll" bgcolor=&q ...
- cordova 开发 ios app 简要流程
1 安装node.js环境 官网: http://nodejs.org/ 点击[install],会下载mac的安装包.正常安装即可 2 安装cordova:npm install -g cordo ...
- Shader之性能优化
1.像素>>顶点数>>物体个数:shader中的计算应首先考虑放在script,其次vert,最后frag中 2.尽量用精度小的类型替换精度大的类型(特别是在frag中,要尽可 ...
- android的MVP模式
MVP简介 相信大家对MVC都是比较熟悉了:M-Model-模型.V-View-视图.C-Controller-控制器,MVP作为MVC的演化版本,那么类似的MVP所对应的意义:M-Model-模型. ...
- 《ArcGIS Runtime SDK for Android开发笔记》
开发笔记之基础教程 ArcGIS Runtime SDK for Android 各版本下载地址 <ArcGIS Runtime SDK for Android开发笔记>——(1).And ...
- Extjs 自动列宽
//auto column width Ext.grid.Panel.prototype.viewConfig = { listeners: { refresh: function (dataview ...
- 【Spring实战】—— 14 传统的JDBC实现的DAO插入和读取
从这篇开始学习Spring的JDBC,为了了解Spring对于JDBC的作用,先通过JDBC传统的流程,实现一个数据库的插入和读取. 从这篇你可以了解到: 1 传统的JDBC插入和读取的过程. 2 如 ...
- JSP实现用户登录样例
业务描述 用户在login.jsp页面输入用户名密码登录: 如果用户名为xingoo,密码为123,则跳转到成功界面login_success.jsp,并显示用户登录的名字: 如果用户名密码错误,则跳 ...
- startup ORA-00845: MEMORY_TARGET not supported on this system
一台虚拟机跑多个实例时,由于/dev/shm空间不够导致如下报错> startupORA-00845: MEMORY_TARGET not supported on this system解决方 ...
- leetcode 198、打家劫舍
You are a professional robber planning to rob houses along a street. Each house has a certain amount ...