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 ...
随机推荐
- python for循环巧妙运用(迭代、列表生成式)
200 ? "200px" : this.width)!important;} --> 介绍 我们可以通过for循环来迭代list.tuple.dict.set.字符串,di ...
- Java I/O---序列化接口Serializable
1.JDK API 中关于Serializable的描述 public interface Serializable 类通过实现 java.io.Serializable 接口以启用其序列化功能.未实 ...
- bzoj 2302: [HAOI2011]Problem c
Description 给n个人安排座位,先给每个人一个1~n的编号,设第i个人的编号为ai(不同人的编号可以相同),接着从第一个人开始,大家依次入座,第i个人来了以后尝试坐到ai,如果ai被占据了, ...
- Linux第六节随笔 输入输出重定向 、管道、通配符、wc / grep / tr / sort / cut / which /whereis /locate /find /
三期第五讲 -高级文件管理1.输入输出重定向 ls -l /dev/stdin -> /proc/self/fd/0 标准输入 设备:键盘 标记:0 ls -l /dev/stdout -> ...
- Parallels Desktop 12
我微新solq123987654 备注:PD 科普:PD12有什么用,PD是让mac系统可以运行wind系统的软件,如果你不习惯mac os 或工作需要那PD绝对是个好软件正版要七八百授权,只要十五就 ...
- Centos7 安装oracle数据库
参考的内容: http://docs.oracle.com/cd/E11882_01/install.112/e24325/toc.htm#CHDCBCJF http://www.cnblogs.co ...
- VS2010 Extension实践(3)——实现自定义配置
在之前的两篇曾提到通过VSSDK(MSDN也叫VSX)来拓宽思路,实现一些MEF Extension所不能做到的功能,比如获取IVsUIShell服务来执行Command等等,这里我给各位看官展示如何 ...
- leetcode — copy-list-with-random-pointer
import java.util.*; /** * * Source : https://oj.leetcode.com/problems/copy-list-with-random-pointer/ ...
- Oracle相关知识做个总结
一.创建用户: 以系统管理员登陆,右键点击Uers进行新建, 一般:默认空间选择USERS,临时表空间选择TEMP,概要文件选择DEFAULT. 对象权限:不做操作. 角色权限:1.connect 2 ...
- jQuery DOM 元素方法 (十)
函数 描述 .get() 获得由选择器指定的 DOM 元素. .index() 返回指定元素相对于其他指定元素的 index 位置. .size() 返回被 jQuery 选择器匹配的元素的数量. . ...