f(cos(x))=cos(n∗x) holds for all xxx.
Given two integers nnn and mmm, you need to calculate the coefficient of xmx^mxm in f(x)f(x)f(x), modulo 998244353998244353998244353.
Input Format
Multiple test cases (no more than 100100100).
Each test case contains one line consisting of two integers nnn and mmm.
1≤n≤109,0≤m≤1041 \le n \le 10^9,0 \le m \le 10 ^ 41≤n≤109,0≤m≤104.
Output Format
Output the answer in a single line for each test case.
样例输入
2 0 2 1 2 2
样例输出
998244352 0 2
题目来源
解题思路:查了一下数列大全,发现是切比雪夫多项式,然后套公式,就出来了。附上队友代码。
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long LL;
const int MOD = 998244353;
/*pwr_mod*/ inline int pwr_mod(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p; } return res; }
/*modulo inverse _p*/ll mod_inv_p(ll n, ll m){ return pwr_mod(n, m-2, m); }
ll n,m;
ll res;
ll regular(ll x){
if(x>=0)return x%MOD;
else return (x+MOD)%MOD;
}
inline ll neg1pow(ll x){
if(x&1)return -1; else return 1;
}
LL Comb(LL a, LL b, LL p) {
if(a < b) return 0;
if(a == b) return 1;
if(b > a - b) b = a - b;
LL ans = 1, ca = 1, cb = 1;
for(LL i = 0; i < b; ++i) {
ca = (ca * (a - i))%p;
cb = (cb * (b - i))%p;
}
ans = (ca*pwr_mod(cb, p - 2, p)) % p;
return ans;
}
LL Lucas(int n, int m, int p) {
LL ans = 1;
while(n&&m&&ans) {
ans = (ans*Comb(n%p, m%p, p)) % p;
n /= p;
m /= p;
}
return ans;
}
ll chebyshev(ll n, ll m){
if((n+m)%2!=0 || n<m)return 0;
else if(m==0){
return neg1pow(n/2);
}
else{
ll part1 = neg1pow((n+m)/2 + m);
ll part2 = pwr_mod(2,m-1,MOD);
ll part3 = n%MOD;
// printf("%lld:%lld:\n",(n+m)/2 - 1, m - 1);
ll part4 = Lucas((n+m)/2 - 1, m - 1,MOD);
ll part5 = mod_inv_p(m,MOD);
// printf("%lld,%lld,%lld,%lld,%lld,\n",part1,part2,part3,part4,part5);
ll part6 = (part1*part2)%MOD;
ll part7 = (part6*part3)%MOD;
ll part8 = (part7*part4)%MOD;
ll part9 = (part8*part5)%MOD;
return part9;
}
}
int main(){
while(~scanf("%lld%lld",&n,&m)){
printf("%lld\n",regular(chebyshev(n,m)));
}
return 0;
}

本文介绍了一种利用切比雪夫多项式计算特定系数的方法,并提供了一个C++程序实现,该程序能够计算给定n和m情况下f(cos(x))=cos(nx)中x^m的系数,所有计算结果取模998244353。
290

被折叠的 条评论
为什么被折叠?



