关闭

2017 ACM-ICPC 亚洲区(西安赛区)网络赛 F.Trig Function(论文+组合数)

标签: 数论组合数
815人阅读 评论(0) 收藏 举报
分类:

传送门

f(cos(x))=cos(nx) holds for all x.

Given two integers n and m, you need to calculate the coefficient of xm in f(x), modulo 998244353.

Input Format

Multiple test cases (no more than 100).

Each test case contains one line consisting of two integers n and m.

1n109,0m104.

Output Format

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




样例输入


2 0 
2 1
2 2



样例输出


998244352 
0
2


题目大意:

给出f(cos(x))=cos(nx) ,求xm前面的系数,其实就是求 cos(x)m 前面的系数。

解题思路:

首先给出论文:传送门
然后就根据论文进行计算就OK了,需要特判两个点。
给出组合数公式:
这里写图片描述
1) m==0 的时候
2) m==n 的时候

代码:

#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <map>
using namespace std;
typedef long long LL;
const int MAXN = 1e4+5;
const double PI = acos(-1);
const double eps = 1e-8;
const LL MOD = 998244353;
LL Pow(LL a, LL b){
    LL ans = 1;
    while(b){
        if(b & 1) ans = ans * a % MOD;
        b>>=1;
        a = a * a % MOD;
    }
    return ans;
}

LL Inv[MAXN];
void Init(){
    Inv[0] = Inv[1] = 1;
    for(int i=2; i<MAXN; i++) Inv[i] = (MOD - MOD / i) * Inv[MOD % i] % MOD;
    for(int i=2; i<MAXN; i++) Inv[i] = Inv[i]*Inv[i-1]%MOD;
}
int main(){
    //freopen("C:/Users/yaonie/Desktop/in.txt", "r", stdin);
    //freopen("C:/Users/yaonie/Desktop/out.txt", "w", stdout);
    Init();
    LL n, m;
    while(~scanf("%lld%lld", &n, &m)){
        if(((n&1)&&!(m&1)) || (!(n&1)&&(m&1))){
            puts("0");
            continue;
        }
        LL k = (n-m)/2;
        if(m == 0){
            if(k & 1) puts("998244352");
            else puts("1");
            continue;
        }
        if(n == m){
            printf("%lld\n",Pow(2LL, n-1));
            continue;
        }
        LL t1 = min(k, n-2*k), t2 = min(k-1, n-2*k);
        LL ans1 = Inv[t1], ans2 = Inv[t2];
        for(LL i=1; i<=t1; i++){
            LL tmp = (n-k-i+1)%MOD;
            ans1 = ans1*tmp%MOD;
        }
        for(LL i=1; i<=t2; i++){
            LL tmp = (n-k-i)%MOD;
            ans2 = ans2*tmp%MOD;
        }
        LL ans = (ans1 + ans2) % MOD;
        if(k & 1) ans=-ans;
        ans = (ans+MOD)%MOD;
        ans = ans*Pow(2LL, n-1-2*k)%MOD;
        printf("%lld\n",ans);
    }
    return 0;
}
0
0
查看评论

2017 ACM-ICPC 亚洲区(西安赛区)网络赛 C.Sum(找规律)

Define the function S(x)S(x) for xx is a positive integer. S(x)S(x) equals to the sum of all digit of the decimal expression of xx. Please find a posi...
  • qq_37497322
  • qq_37497322
  • 2017-09-16 17:49
  • 384

2017 ACM-ICPC 西安赛区 网络赛 F. Trig Function 【规律题】

2017 ACM-ICPC 西安赛区 网络赛 F. Trig Function 【规律题】 Problem Description f(cos(x))=cos(n∗x) holds for all x. Given two integersn and m , you need to calcula...
  • my_sunshine26
  • my_sunshine26
  • 2017-09-16 19:14
  • 703

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

题目来源:Sum 1000ms 32768K Define the function S(x) for xx is a positive integer. S(x) equals to the sum of all digit of the decimal expression of x. ...
  • Enterprise_
  • Enterprise_
  • 2017-09-16 16:47
  • 223

ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A. Visiting Peking University(模拟水题)

Ming is going to travel for n days and the date of these days can be represented by n integers: 0, 1, 2, …, n-1. He plans to spend m consecutive days(...
  • qq_37497322
  • qq_37497322
  • 2017-09-23 17:00
  • 474

ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题解汇总 Territorial Dispute

ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 题解汇总 Territorial Dispute
  • axuhongbo
  • axuhongbo
  • 2017-09-24 09:02
  • 976

2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 L. The Heaviest Non-decreasing Subsequence Problem

Let SS be a sequence of integers s_{1}s​1​​, s_{2}s​2​​, ......, s_{n}s​n​​ Each integer is is associated with ...
  • lzc504603913
  • lzc504603913
  • 2017-09-24 17:46
  • 549

ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 E Territorial Dispute (凸包)

Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Java Republic become the most powerful country in the world....
  • Ever_glow
  • Ever_glow
  • 2017-09-23 20:56
  • 926

ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A. Visiting Peking University

ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 A. Visiting Peking University
  • axuhongbo
  • axuhongbo
  • 2017-09-24 08:16
  • 566

2017 ICPC 西安站现场赛总结&部分题解

关于别墅:别墅很Nice,除了Wifi有点差之外都很棒,晚上还可以去健身房玩耍,早餐特别棒,前台的小哥哥也是很热情!给秦龙打Call! 关于学校:能看得出校方是重视这次比赛的,准备的很充分,给了饭票,如果不想吃统一的盖浇饭还可以自己买餐,同时原来的餐票可以换取任意四瓶饮料,美滋滋,陕西的面...
  • calabash_boy
  • calabash_boy
  • 2017-10-30 11:01
  • 978

ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛 G Bounce (规律)

Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a circle bouncing in a rectangle. As shown in the figure below...
  • Ever_glow
  • Ever_glow
  • 2017-09-24 09:36
  • 1023
    个人资料
    • 访问:530421次
    • 积分:11569
    • 等级:
    • 排名:第1585名
    • 原创:639篇
    • 转载:5篇
    • 译文:0篇
    • 评论:93条
    博客专栏