Computing the exact number of ways that N things can be taken M at a time can be a great challenge when N and/or M become very large. Challenges are the stuff of contests. Therefore, you are to make just such a computation given the following:
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

The input to this program will be one or more lines each containing zero or more leading spaces, a value for N, one or more spaces, and a value for M. The last line of the input file will contain a dummy N, M pair with both values equal to zero. Your program should terminate when this line is read.

Output

The output from this program should be in the form:

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的更多相关文章

随机推荐

  1. 编程提取字符串"Java is a programming language"中的各个单词,并打印输出。

    import java.lang.String; import java.util.StringTokenizer; public class StringGetWord{ /* 编程提取字符串&qu ...

  2. CSS3控制单行文本的溢出

    text-overflow用来设置是否使用一个省略标记(...)标示对象内文本的溢出.语法: 但是text-overflow只是用来说明文字溢出时用什么方式显示,要实现溢出时产生省略号的效果,还须定义 ...

  3. Div+Css布局教程(-)CSS必备知识

    目录: 1.Div+Css布局教程(-)CSS必备知识 注:本教程要求对html和css有基础了解. 一.CSS布局属性 Width:设置对象的宽度(width:45px). Height:设置对象的 ...

  4. 多线程(四)~数据操作的原子性,使用原子性操作AutomicInteger替换非原子性的i++的操作

    这一章,我们要来验证volatile关键字不是原子性的,OK,还是用代码来说话. ①.线程类,操作i++ 500次 package com.multiThread.thread; publicclas ...

  5. github代码上传教程

    github 上传代码步骤 一.git以及Github Git是个正快速成长的版本控制系统,它由GitHub维护. 优势: 1.支持离线开发,离线Repository. 2.强大的分支功能,适合多个独 ...

  6. Informatica学习笔记

    Informatica学习笔记1:UPDATE AS INSERT 问:要求实现每天抽取数据,而且是如果有改变才抽取更新,没有就不更新,因为源表中有最后修改时间的字段,我让它 和SESSION上次运行 ...

  7. 签名&加密的区别

    https://www.zhihu.com/question/27669212/answer/38037256 就拿A给B发送经过签名加密信息来说: 1.A对信息签名的作用是确认这个信息是A发出的,不 ...

  8. 《O2O实战:二维码全渠道营销》读书笔记思维导图(530KB)

  9. 2.LVS配置过程

    请查看我的有道云笔记: http://note.youdao.com/noteshare?id=866edb5736418d29c86d68b5198c5c1c&sub=66F88F0A24D ...

  10. GridView中的更新按钮不能触发RowUpdating事件

    当点击“编辑”按钮以后,可以看到“更新”和“取消”按钮,“取消”按钮可以正常触发RowCancelingEdit事件,但是“更新”按钮不能触发RowUpdating事件. 解决方案: 在<asp ...