2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F. Trig Function

来源:互联网 发布:淘宝退货邮费谁承担 编辑:程序博客网 时间:2024/06/05 10:40

f(cos(x))=cos(nx) 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 ^ 41n109,0m104.

Output Format

Output the answer in a single line for each test case.

样例输入

2 02 12 2

样例输出

99824435202

题目来源

2017 ACM-ICPC 亚洲区(西安赛区)网络赛


解题思路:查了一下数列大全,发现是切比雪夫多项式,然后套公式,就出来了。附上队友代码。



#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;}


阅读全文
0 0
原创粉丝点击