「NOIP2011」计算系数 题解
「NOIP2011」计算系数
题意
给定一个多项式 ,求多项式展开后项的系数。
解
二项式定理科普
完了,就是板子题。
显然这个多项式还要乘上一个
Code
#include <bits/stdc++.h> using i64 = long long; inline i64 read(){ i64 x = 0, f = 1;char ch = getchar(); while (ch < '0' || ch > '9') f = ch == '-' ? -1 : 1, ch = getchar(); while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); return x * f; } inline void print(i64 x){ char P[105];i64 w=0;if(x==0){putchar('0');return;} if(x<0) putchar('-'),x=(~x) + 1; while(x) P[++w]=x%10+'0',x/=10; for(i64 i=w; i>=1; i--) putchar(P[i]); } constexpr int p = 10007; i64 n, m; inline i64 q_pow(i64 a, i64 b){ i64 ans = 1; while (b) { if (b & 1) ans = (ans * a) % p; a = (a * a) % p; b >>= 1; } return ans; } inline i64 c(i64 n, i64 m) { i64 ans1 = 1, ans2 = 1; while (m) { ans1 = (ans1 * n) % p; ans2 = (ans2 * m) % p; n--, m--; } i64 Ans = 1ll * ans1 * q_pow(ans2, p - 2) % p; return Ans; } inline i64 lucas(i64 n, i64 m) { return m == 0 ? 1 : (c(n % p, m % p) * lucas(n / p, m / p) % p); } inline void solve() { int a = read(), b = read(), k = read(); n = read(), m = read(); print((lucas(k, n) * q_pow(a, n) % p * q_pow(b, m) % p)% p); putchar('\n'); } int main() { solve(); return 0; }
本文作者:Falling-flowers 的 blog
本文链接:https://www.cnblogs.com/falling-flowers/p/15876602.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步