Pool

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

요약
너비 N, 높이 1001인 격자에서 각 칸이 확률 q로 독립적으로 안전할 때, 해변에 붙은 가장 큰 안전 직사각형의 넓이가 정확히 K일 확률을 소수로 나눈 나머지를 구한다.
난이도

어려움10점 중 8점

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

문제

There is a pool that can be modeled as a rectangular grid with width NN meters and height 1001 meters. The bottom edge of the grid corresponds to a beach. Each 1m×1m1m \times 1m square cell of the grid represents a unit of sea.

A safe area for swimming shall satisfy the following constraints:

  • All cells in the pool are safe.
  • Must be rectangular.
  • Must be adjacent to the bottom edge (i.e. the beach).

Given that each square cell of 1m×1m1m \times 1m has probability qq to be safe (independently), and 1−q1-q probability to be not safe, find the probability such that the largest safe area for swimming is exactly KK.

입력

Input a line with four positive integers N,K,x,yN,K,x,y where 1≤x<y<9982443531 \leq x < y < 998244353. The parameter qq is just xy\frac{x}{y}.

출력

Output a line with an integer denoting the answer modulo 998244353: if the answer is ab\frac{a}{b} in reduced form (i.e. aa and bb are coprime), then output xx such that bx≡a mod 998244353bx \equiv a \bmod 998244353 and 0≤x<9982443530 \leq x < 998244353.

제한

  • 1≤N≤1091 \leq N \leq 10^9
  • 1≤K≤10001 \leq K \leq 1000

힌트

xp−1≡1 mod px^{p-1} \equiv 1 \bmod p where pp is prime and x∈\[1,p)x \in \[1,p).

예제1

  1. 예제 1

    입력
    10 5 1 2
    
    예상 출력
    342025319