Nonsense

시간 제한1초메모리 제한1024 MB

요약
각 질의 (a,b)마다 매우 큰 n과 x, y를 사용한 이항계수 곱의 가중합을 998244353으로 나눈 나머지를 구한다.
난이도

어려움10점 중 8점

유형
조합론, 수학, 동적 계획법, 정수론
정답자
아직 제출이 없습니다

문제

Given nn, xx and yy, let f_n,x,y(a,b)f\_{n, x, y}(a, b) denote the value of ∑_i=an−b(ia)xi−a(n−ib)yn−i−b. \sum\_{i = a}^{n - b} \binom{i}{a} x^{i - a} \binom{n - i}{b} y^{n - i - b}\text{.}

Bobo also has qq pairs (a_1,b_1),…,(a_q,b_q)(a\_1, b\_1), \dots, (a\_q, b\_q). Find the value of f_n,x,y(a_1,b_1),…,f_n,x,y(a_q,b_q)f\_{n, x, y}(a\_1, b\_1), \dots, f\_{n, x, y}(a\_q, b\_q) modulo 998244353998244353.

Note: (nk)=n!(n−k)!k!.\binom{n}{k} = \frac{n!}{(n - k)! k!}\text{.}

입력

The input consists of several test cases terminated by end-of-file. For each test case,

The first line contains four integers nn, xx, yy and qq.

In the following qq lines, the ii-th line contains two integers a_ia\_i and b_ib\_i.

출력

For each pair, output an integer which denotes the value modulo 998244353998244353.

제한

  • 2≤n≤1092 \leq n \leq 10^9
  • 0≤x,y<9982443530 \leq x, y < 998244353
  • 1≤q≤2×1051 \leq q \leq 2 \times 10^5
  • 1≤a_i,b_i≤50001 \leq a\_i, b\_i \leq 5000 for each 1≤i≤q1 \leq i \leq q
  • a_i+b_i≤na\_i + b\_i \leq n for each 1≤i≤q1 \leq i \leq q
  • In each input, the sum of max⁡(a_1,b_1,…,a_q,b_q)\max(a\_1, b\_1, \dots, a\_q, b\_q) does not exceed 50005000. The sum of qq does not exceed 2×1052 \times 10^5.

예제1

  1. 예제 1

    입력
    3 1 2 2
    1 1
    1 2
    100 2 3 1
    1 1
    
    예상 출력
    6
    1
    866021789