f(cos(x))=cos(n∗x) holds for all xx.
Given two integers nn and mm, you need to calculate the coefficient of x^mxm in f(x)f(x), modulo 998244353998244353.
Input Format
Multiple test cases (no more than 100100).
Each test case contains one line consisting of two integers nn and mm.
1 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
题意 求第n个柿子中x的m次方系数
公式 http://www.docin.com/p-385138324.html
1 #include <stdio.h> 2 #include <math.h> 3 #include <string.h> 4 #include <stdlib.h> 5 #include <iostream> 6 #include <sstream> 7 #include <algorithm> 8 #include <string> 9 #include <queue> 10 #include <vector> 11 using namespace std; 12 const int maxn = 1e4+10; 13 const int maxm = 1e4+5; 14 const int mod = 998244353; 15 typedef long long ll; 16 ll a[5]={1,0,-1,0}; //m=0规律 四个数循环 17 ll n,m; 18 ll jie(ll m) // 阶乘 19 { 20 21 ll j=1; 22 for(ll i=1;i<=m;i++) 23 j=(j*i)%mod; //每步都取余 24 return j; 25 } 26 ll jie2(ll n,ll m) //双阶乘 27 { 28 ll j=1; 29 for(ll i=n-m+2;i<=n+m-2;i+=2) 30 j=(j*i)%mod; 31 return j; 32 } 33 //ll inv(ll t, ll p) //求t关于p的逆元,注意:t要小于p,最好传参前先把t%p一下 34 //{ 35 // return t == 1 ? 1 : (p - p / t) * inv(p % t, p) % p; 36 //} 37 ll qmod(ll n,ll m) //快速幂 38 { 39 ll ans = 1; 40 while(m > 0) 41 { 42 if(m & 1) 43 ans = (ans * n) % mod; 44 m = m >> 1; 45 n = (n * n) % mod; 46 } 47 return ans; 48 } 49 int main(int argc, char const *argv[]) 50 { 51 while(scanf("%lld %lld",&n,&m)!=EOF) 52 { 53 if(m>n) 54 printf("0 "); 55 else if((n-m)%2) //n,m奇偶性不同直接输出0 56 printf("0 "); 57 else if(m>0) //相同用公式 58 { 59 ll ans=n%mod; //单独的一个n 60 ans=ans*jie2(n,m)%mod; //n+m-2的双阶乘//n-m 的双阶乘 结果的 逆元 乘ans 61 ans=ans*qmod(jie(m),mod-2)%mod; // m 的阶乘的 结果的 逆元 乘ans 62 if((n-m)/2%2==1) //判断正负符号 63 ans=-ans; 64 printf("%lld ",(ans+mod)%mod); 65 } 66 else //m=0特判 67 { 68 printf("%lld ",(a[n%4]+mod)%mod); 69 } 70 } 71 return 0; 72 }