(思维)CSL 的神奇序列

链接:https://ac.nowcoder.com/acm/contest/551/F
来源:牛客网
 

时间限制:C/C++ 2秒,其他语言4秒
空间限制:C/C++ 524288K,其他语言1048576K
64bit IO Format: %lld

题目描述

CSL 有一个神奇的无穷实数序列,他的每一项满足如下关系:

对于任意的正整数 n ,有 n∑k=0akan−k=w2∑k=0nakan−k=w2 , 并且 a0=wa0=w 。

CSL 很清楚这样的序列是唯一的,他现在想考考你,你能快速告诉他这个序列的第 n 项是多少吗?
 

为了不让你感到难过,对每次询问你只要输出 2nn!2nn! 倍的 anan 对 998244353 取模后的结果即可。

输入描述:

第一行有两个整数 w 和 q ,其中 w 的含义如题意所述, q 表示接下来的询问次数。

接下来的 q 行,每行输入一个数 n 。

1≤w,n≤1061≤w,n≤106
1≤q≤1051≤q≤105

输出描述:

对于每一次询问, 在一行输出一个整数 v ,表示 v=2nn!⋅anmod 998244353v=2nn!⋅anmod 998244353

示例1

输入

复制

1 2
1
2

输出

复制

1
3

题解 : w为1举例:

扫描二维码关注公众号,回复: 5737460 查看本文章

             第0项:1/1   

             第1项:1/2    -->  1

             第2项:3/8   --->   3

             第3项:5/16  --->  15/48   --->  15

             ...............

#include<set>
#include<map>
#include<list>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<bitset>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define eps (1e-8)
#define MAX 0x3f3f3f3f
#define u_max 1844674407370955161
#define l_max 9223372036854775807
#define i_max 2147483647
#define re register
#define pushup() tree[rt]=tree[rt<<1]+tree[rt<<1|1]
#define nth(k,n) nth_element(a,a+k,a+n);  // 将 第K大的放在k位
#define ko() for(int i=2;i<=n;i++) s=(s+k)%i // 约瑟夫
#define ok() v.erase(unique(v.begin(),v.end()),v.end()) // 排序,离散化
#define Catalan C(2n,n)-C(2n,n-1)  (1,2,5,14,42,132,429...) // 卡特兰数
using namespace std;

inline int read(){
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' & c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

typedef long long ll;
const double pi = atan(1.)*4.;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;
const int M=63;
const int N=1e6+5;
ll mod=998244353;
int n,q,m;
ll a[N];
void fun(){
    a[1]=n;
    for(int i=2;i<N;i++)
        a[i]=a[i-1]*(i*2-1)%mod;
}
int main(){
    scanf("%d %d",&n,&q);
    fun();
    while(q--){
        scanf("%d",&m);
        printf("%lld\n",a[m]);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/black_horse2018/article/details/88935366