4826 Problem A 计算组合数

问题 A: 计算组合数
时间限制: 1 Sec 内存限制: 128 MB
献花: 22 解决: 21
[献花][花圈][TK题库]
题目描述
编制程序,输入m,n(M>=n>=0)后,计算下列表达式的值并输出:
这里写图片描述
要求将计算阶乘运算的函数写为fact(n),函数返回值的类型为float
输入
m n
输出
对应表达式的值
样例输入
2 1
样例输出
2

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cstring>
#include <string>

using namespace std;

typedef long long LL;

LL C(LL m, LL n)
{
    LL res = 1;
    for (LL i = 1,D  = m - n; i <= D; ++i)
    {
        res = res * (m - i + 1) / i;
    }
    return res;
}
int main()
{
#ifdef _DEBUG
    freopen("data.txt", "r+", stdin);
#endif // _DEBUG

    LL m, n;  
    while (cin >> m >> n)
    {
        cout << C(m, n) << endl;
    }

    return 0;
}
/**************************************************************
    Problem: 4826
    User: Sharwen
    Language: C++
    Result: 升仙
    Time:0 ms
    Memory:1704 kb
****************************************************************/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值