您的位置:首页 > 理论基础 > 计算机网络

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

2017-09-16 23:18 519 查看
f(cos(x))=cos(n∗x)
holds for all xxx.
Given two integers nnn
and mmm,
you need to calculate the coefficient of xmx^mx​m​​
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≤10​9​​,0≤m≤10​4​​.

Output Format

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

样例输入

2 0
2 1
2 2


样例输出

998244352
0
2


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<cstdlib>
#include<string>
#include<set>
#include<stack>
#define mod 998244353

using namespace std;

int n, k;

long long  PowerMod(long long  a, long long  b = mod - 2, long long c = mod)
{
long long  ans = 1;
a = a % c;
while(b>0)
{
if(b & 1)
ans = (ans * a) % c;
b >>= 1;
a = (a * a) % c;
}
return ans;
}
void xishu()
{
long long ans = 1;
if((n & 1) + (k & 1) == 1)
{
cout << 0 << endl;
return ;
}
else
{
int tmp = (n - k) / 2;
if(tmp & 1)
ans = -1;
else
ans = 1;
}
for(int i = 1; i <= k; i++)
{
ans = ans * PowerMod(i) % mod;
}
int low = min(n + k - 2, n - k);
int high = max(n + k - 2, n - k);
if(n + k - 2 <= n - k)
{
for(int i = high ; i > low ; i -= 2)
{
ans = ans * PowerMod(i) % mod;
}
}
else
{
for(int i = high; i > low; i -= 2)
{
ans = ans * i % mod;
}
}
ans = ans * n % mod;
cout << (ans + mod) % mod << endl;
}

int main()
{
while(~scanf("%d %d", &n, &k))
{
xishu();
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm-icpc c++ 亚洲 网络