2017西安网络赛 F
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
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn = 1e4+;
const int maxm = 1e4+;
const int mod = ;
typedef long long ll;
ll a[]={,,-,}; //m=0规律 四个数循环
ll n,m;
ll jie(ll m) // 阶乘
{ ll j=;
for(ll i=;i<=m;i++)
j=(j*i)%mod; //每步都取余
return j;
}
ll jie2(ll n,ll m) //双阶乘
{
ll j=;
for(ll i=n-m+;i<=n+m-;i+=)
j=(j*i)%mod;
return j;
}
//ll inv(ll t, ll p) //求t关于p的逆元,注意:t要小于p,最好传参前先把t%p一下
//{
// return t == 1 ? 1 : (p - p / t) * inv(p % t, p) % p;
//}
ll qmod(ll n,ll m) //快速幂
{
ll ans = ;
while(m > )
{
if(m & )
ans = (ans * n) % mod;
m = m >> ;
n = (n * n) % mod;
}
return ans;
}
int main(int argc, char const *argv[])
{
while(scanf("%lld %lld",&n,&m)!=EOF)
{
if(m>n)
printf("0\n");
else if((n-m)%) //n,m奇偶性不同直接输出0
printf("0\n");
else if(m>) //相同用公式
{
ll ans=n%mod; //单独的一个n
ans=ans*jie2(n,m)%mod; //n+m-2的双阶乘//n-m 的双阶乘 结果的 逆元 乘ans
ans=ans*qmod(jie(m),mod-)%mod; // m 的阶乘的 结果的 逆元 乘ans
if((n-m)/%==) //判断正负符号
ans=-ans;
printf("%lld\n",(ans+mod)%mod);
}
else //m=0特判
{
printf("%lld\n",(a[n%]+mod)%mod);
}
}
return ;
}
2017西安网络赛 F的更多相关文章
- 2017 ACM-ICPC 西安网络赛 F.Trig Function Chebyshev多项式
自己太菜,数学基础太差,这场比赛做的很糟糕.本来想吐槽出题人怎么都出很数学的题,现在回过头来想还是因为自己太垃圾,竞赛就是要多了解点东西. 找$f(cos(x))=cos(nx)$中$x^m$的系数模 ...
- 2017西安网络赛B_Coin
样例输入 2 2 1 1 3 1 2 样例输出 500000004 555555560 思路: n重伯努利实验概率分布题. 设q=1-p,p为事件概率. Y为出现偶数次的概率. 所以 Y=1/2*( ...
- 2017西安网络赛C_SUM
样例输入 1 1 样例输出 89999999999999999999999999 题意:利用上述公式,求出k的值 思路:找规律,找规律发现233个9,无论x是何值永远成立 (这种规律题尽量就不用跟队友 ...
- 2017北京网络赛 F Secret Poems 蛇形回路输出
#1632 : Secret Poems 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 The Yongzheng Emperor (13 December 1678 – ...
- hdu5017:补题系列之西安网络赛1011
补题系列之西安网络赛1011 题目大意:给定一个椭球: 求它到原点的最短距离. 思路: 对于一个椭球的标准方程 x^2/a^2 + y^2/b^2 +z^2/c^2=1 来说,它到原点的最短距离即为m ...
- ACM-ICPC 2019南昌网络赛F题 Megumi With String
ACM-ICPC 南昌网络赛F题 Megumi With String 题目描述 给一个长度为\(l\)的字符串\(S\),和关于\(x\)的\(k\)次多项式\(G[x]\).当一个字符串\(str ...
- 2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F. Trig Function(切比雪夫多项式+乘法逆元)
题目链接:哈哈哈哈哈哈 _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ 哈哈哈哈哈哈,从9月16日打了这个题之后就一直在补这道题,今天终于a了,哈哈哈哈哈哈. ...
- 计蒜客 17119.Trig Function-切比雪夫多项式+乘法逆元 (2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F)
哈哈哈哈哈哈哈哈哈哈哈哈,终于把这道题补出来了_(:з」∠)_ 来写题解啦. _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ _(:з」∠)_ 哈哈哈哈哈哈,从9月16日打了这 ...
- 2017 ICPC网络赛(西安)--- Xor
题目连接 Problem There is a tree with n nodes. For each node, there is an integer value ai, (1≤ai≤1,000 ...
随机推荐
- spring boot使用profile来区分正式环境配置文件与测试环境配置文件
转载请在页首注明作者与出处 一:前言 经常在开发的时候,项目中的配置文件,在个人开发的时候有一套配置文件,在测试环境有一套配置文件,在正式环境有一套配置文件,这个时候如果配置文件复杂,需要改的东西就特 ...
- CSS line-height概念与举例
本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/37 定义 两行文字基线之间的距离. 基线的大体位置 基线的位置可 ...
- verilog抓外部低频输入信号的上升沿和下降沿
版权申明:本文为博主窗户(Colin Cai)原创,欢迎转帖.如要转贴,必须注明原文网址 http://www.cnblogs.com/Colin-Cai/p/7220107.html 作者:窗户 Q ...
- 利用VSTS跟Kubernetes进行CI/CD
准备VSTS管理环境 首先我们需要到www.visualstudio.com下申请好的VSTS账号,然后在账号下创建一个用Git作为代码管理的项目 创建好项目后我们就可以利用git clone将代码库 ...
- Macaca自动化工具之uirecorder脚本录制
UI Recorder功能介绍 支持所有用户行为: 键盘事件, 鼠标事件, alert, 文件上传, 拖放, svg, shadow dom 支持无线native app录制, 基于macaca实现: ...
- 开发中关于Git那些事(续:Git变基)
其实上一篇写的内容仅仅是Git的冰山一角,如果你认为Git就是简简单单的几行命令,那只能说明你还没有真正了解Git这个强大的内容寻址文件系统.这篇文章,还是接着介绍一些实用但是很少有人知晓的一些命令, ...
- angularjs 怎么获取鼠标焦点 鼠标移入显示浮动的div提示框
首先,我们要清楚几个基础的知识,angular的两个鼠标移入移出的指令------ng-mouseover(鼠标移入)ng-mouseleave(鼠标移出)--------还有就是window.eve ...
- LeetCode题目总结(一)
我的代码在github上,https://github.com/WINTERFELLS/LeetCode-Answers 这里只提供个人的解题思路,不一定是最好的. Problems1-20 寻找两个 ...
- Validation of viewstate MAC failed 解决办法
大部分人都说是在页里或web.config里加EnableEventValidation="false" EnableViewStateMac="false" ...
- chrome console的使用 : 异常和错误的处理 – Break易站
本文内容来自:chrome console的使用 : 异常和错误的处理 – Break易站 利用 Chrome DevTools 提供的工具,您可以修复引发异常的网页和在 JavaScript 中调试 ...