牛客计算系数(Lucas+二项式定理)

题目链接
隐隐约约记得展开式和组合数的关系,但是记不起来,百度了才知道二项式定理。
( x + y ) n = C ( n , 0 ) × x n × y 0 + C ( n , 1 ) × x n − 1 × y 1 + C ( n , 2 ) × x n − 2 × y 2 . . . . . . + C ( n , n ) × x 0 × y n (x+y)^n=C(n,0)\times x^n \times y^0+C(n,1)\times x^{n-1} \times y^1+C(n,2)\times x^{n-2} \times y^2......+C(n,n)\times x^0 \times y^n (x+y)n=C(n,0)×xn×y0+C(n,1)×xn1×y1+C(n,2)×xn2×y2......+C(n,n)×x0×yn
知道二项式定理之后就是一个裸题了
答案就是 C ( k , n ) × a n × b m C(k,n)\times a^n\times b^m C(k,n)×an×bm

AC代码:

/*
 * @Author: hesorchen
 * @Date: 2020-04-14 10:33:26
 * @LastEditTime: 2020-06-30 22:12:29
 * @Link: https://hesorchen.github.io/
 */
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define endl '\n'
#define PI acos(-1)
#define PB push_back
#define ll long long
#define INF 0x3f3f3f3f
#define mod 10007
#define pll pair<ll, ll>
#define lowbit(abcd) (abcd & (-abcd))
#define max(a, b) ((a > b) ? (a) : (b))
#define min(a, b) ((a < b) ? (a) : (b))

#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define FRE                              \
    {                                    \
        freopen("in.txt", "r", stdin);   \
        freopen("out.txt", "w", stdout); \
    }

inline ll read()
{
    ll x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = (x << 1) + (x << 3) + (ch ^ 48);
        ch = getchar();
    }
    return x * f;
}
//==============================================================================
ll quick_pow(ll a, ll b)
{
    ll res = 1;
    while (b)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b /= 2;
    }
    return res % mod;
}
ll jc[2500];
void init()
{
    jc[0] = 1;
    for (int i = 1; i < 2345; i++)
        jc[i] = jc[i - 1] * i % mod;
}
ll C(ll n, ll m)
{
    ll a = n % mod;
    ll b = m % mod;
    if (a < b)
        return 0;
    if (a && b)
        return jc[a] * quick_pow(jc[b], mod - 2) % mod * quick_pow(jc[a - b], mod - 2) % mod * C(n / mod, m / mod) % mod;
    else
        return 1;
}
int main()
{
    ll a, b, k, n, m;
    cin >> a >> b >> k >> n >> m;
    init();
    cout << C(k, n) * quick_pow(a, n) * quick_pow(b, m) % mod << endl;
    return 0;
}
/*
*/
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hesorchen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值