Description
已知多项式函数 f f 满足,问 f(x) f ( x ) 的 xm x m 项的系数
Input
多组用例,每组用例输入两个整数 n,m(1≤n≤109,0≤m≤104) n , m ( 1 ≤ n ≤ 10 9 , 0 ≤ m ≤ 10 4 )
Output
输出 f(x) f ( x ) 的 xm x m 项的系数,结果模 998244353 998244353
Sample Input
2 0
2 1
2 2
Sample Output
998244352
0
2
Solution
f f 即为第个第一类切比雪夫多项式
第一类切比雪夫多项式 Pn(x)=cos(n×arccosx) P n ( x ) = c o s ( n × a r c c o s x ) 的显示表达:
P2n(x)=∑k=0n(−1)n−k(22kCn−kn+k−22k−1Cn−kn+k+1)x2k P 2 n ( x ) = ∑ k = 0 n ( − 1 ) n − k ( 2 2 k C n + k n − k − 2 2 k − 1 C n + k + 1 n − k ) x 2 k
P2n+1(x)=∑k=0n(−1)n−k(22k+1Cn−kn+k+1−22kCn−kn+k)x2k+1 P 2 n + 1 ( x ) = ∑ k = 0 n ( − 1 ) n − k ( 2 2 k + 1 C n + k + 1 n − k − 2 2 k C n + k n − k ) x 2 k + 1
注意到 Cn−kn+k=C2kn+k C n + k n − k = C n + k 2 k ,故求组合数的时间复杂度为 O(mlogp) O ( m l o g p ) ,其中 p p <script type="math/tex" id="MathJax-Element-16">p</script>为模数
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=100001;
#define mod 998244353
int mod_pow(int a,int b)
{
if(b<0)return 0;
int ans=1;
while(b)
{
if(b&1)ans=(ll)ans*a%mod;
a=(ll)a*a%mod;
b>>=1;
}
return ans;
}
int C(int n,int m)
{
if(m<0||m>n)return 0;
int ans=1;
for(int i=1;i<=m;i++)
{
ans=(ll)ans*(n-i+1)%mod;
ans=(ll)ans*mod_pow(i,mod-2)%mod;
}
return ans;
}
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
if(((n+m)&1)||m>n)printf("0\n");
else
{
int ans=0;
if(n&1)
{
n/=2,m/=2;
ans=(ll)mod_pow(2,2*m+1)*C(n+m+1,2*m+1)%mod;
ans-=(ll)mod_pow(2,2*m)*C(n+m,2*m)%mod;
if(ans<0)ans+=mod;
if((n-m)&1)ans=(mod-ans)%mod;
}
else
{
n/=2,m/=2;
ans=(ll)mod_pow(2,2*m)*C(n+m,2*m)%mod;
ans-=(ll)mod_pow(2,2*m-1)*C(n+m-1,2*m-1)%mod;
if(ans<0)ans+=mod;
if((n-m)&1)ans=(mod-ans)%mod;
}
ans=(ans%mod+mod)%mod;
printf("%d\n",ans);
}
}
return 0;
}