zoukankan      html  css  js  c++  java
  • P1313 计算系数

    题目描述

    给定一个多项式(by+ax)^k,请求出多项式展开后x^n*y^m 项的系数。

    输入输出格式

    输入格式:

    输入文件名为factor.in。

    共一行,包含5 个整数,分别为 a ,b ,k ,n ,m,每两个整数之间用一个空格隔开。

    输出格式:

    输出共1 行,包含一个整数,表示所求的系数,这个系数可能很大,输出对10007 取模后的结果。

    输入输出样例

    输入样例#1: 复制
    1 1 3 1 2
    
    输出样例#1: 复制
    3

    说明

    【数据范围】

    对于30% 的数据,有 0 ≤k ≤10 ;

    对于50% 的数据,有 a = 1,b = 1;

    对于100%的数据,有 0 ≤k ≤1,000,0≤n, m ≤k ,且n + m = k ,0 ≤a ,b ≤1,000,000。

    计算

    ans=b^m*a^n*C(k,n)

    快速幂+分解质因数求解C(k,n)

    // 去吧!皮卡丘! 把AC带回来!
    //      へ     /|
    //   /\7    ∠_/
    //   / │   / /
    //  │ Z _,< /   /`ヽ
    //  │     ヽ   /  〉
    //  Y     `  /  /
    //  イ● 、 ●  ⊂⊃〈  /
    //  ()  へ    | \〈
    //   >ー 、_  ィ  │ //
    //   / へ   / ノ<| \\
    //   ヽ_ノ  (_/  │//
    //    7       |/
    //    >―r ̄ ̄`ー―_
    //**************************************
    #pragma comment(linker, "/STACK:1024000000,1024000000")
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define inf 2147483647
    const ll INF = 0x3f3f3f3f3f3f3f3fll;
    #define ri register int
    template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); }
    template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); }
    template <class T> inline T min(T a, T b, T c, T d) {
      return min(min(a, b), min(c, d));
    }
    template <class T> inline T max(T a, T b, T c, T d) {
      return max(max(a, b), max(c, d));
    }
    #define scanf1(x) scanf("%d", &x)
    #define scanf2(x, y) scanf("%d%d", &x, &y)
    #define scanf3(x, y, z) scanf("%d%d%d", &x, &y, &z)
    #define scanf4(x, y, z, X) scanf("%d%d%d%d", &x, &y, &z, &X)
    #define pi acos(-1)
    #define me(x, y) memset(x, y, sizeof(x));
    #define For(i, a, b) for (int i = a; i <= b; i++)
    #define FFor(i, a, b) for (int i = a; i >= b; i--)
    #define bug printf("***********
    ");
    #define mp make_pair
    #define pb push_back
    const int maxn = 3e5 + 10;
    const int maxx = 1e6 + 10;
    // name*******************************
    int a, b, k, n, m;
    ll ans = 1;
    int cnt[2000];
    int mod = 10007;
    // function******************************
    //快速幂
    ll qmul(ll a, ll b) {
      ll base = a, ans = 1;
      while (b) {
        if (b & 1)
          ans = ans * base % mod;
        base = base * base % mod;
        b >>= 1;
      }
      return ans;
    }
    //分解质因数
    void cal(int x, int v) { int y = x; for (int i = 2; i <= x; i++) { while (y % i == 0) { y /= i; cnt[i] += v; } } } //*************************************** int main() { // ios::sync_with_stdio(0); cin.tie(0); // freopen("test.txt", "r", stdin); // freopen("outout.txt","w",stdout); cin >> a >> b >> k >> n >> m; For(i, m + 1, k) cal(i, 1); For(i, 2, n) cal(i, -1); For(i, 2, k) { if (cnt[i]) ans = ans * qmul(i, cnt[i]) % mod; } ans = ans * qmul(b, m) % mod; ans = ans * qmul(a, n) % mod; cout << ans; return 0; }
  • 相关阅读:
    Django级联删除的选项
    Mysql远程连接配置
    Node.js中http-server的使用
    MySQL大小写问题
    将Mysql的一张表导出至Excel格式文件
    图像处理之直方图均衡化及C源码实现
    图像处理之双边滤波介绍与源码实现
    图像滤波之高斯滤波介绍
    图像处理之中值滤波介绍及C实现
    图像处理之均值滤波介绍及C算法实现
  • 原文地址:https://www.cnblogs.com/planche/p/8556900.html
Copyright © 2011-2022 走看看