Zig-zag

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

요약
자연수 n을 양의 정수들의 합으로 나타낼 때, 인접한 항이 번갈아 오르내리는 지그재그 수열이 되는 가짓수를 998244353으로 나눈 나머지로 구한다. 질의는 최대 300000개다.
난이도

보통10점 중 7점

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

문제

Zack’s Zergonomics Zegree has taught him that the optimal way to display items in a store is to stack them into a zig-zag pattern.

Zack needs to display nn boxes lined up on the storefront, each one containing an action figure. These boxes can be stacked on top of one another, and they are identical and indistinguishable from each other. His goal is to decide the number of stacks, and then stack up the boxes such that each stack is non-empty, and the numbers of boxes in the stacks form a zig-zag sequence.

Formally, if there are ss (s≥1s ≥ 1) stacks numbered 11 to ss from left to right, and stack ii contains a_ia\_i boxes, then the following conditions must be satisfied:

  • a_i≥1a\_i ≥ 1 for each ii from 11 to ss,

  • a_1+a_2+⋯+a_s=na\_1 + a\_2 + \dots + a\_s = n, and

  • at least one of the following is true:

    • a_1<a_2>a_3<a_4>…a\_1 < a\_2 > a\_3 < a\_4 > \dots, or
    • a_1>a_2<a_3>a_4<…a\_1 > a\_2 < a\_3 > a\_4 < \dots

For example, for n=6n = 6, there are 1212 ways as illustrated by Figure M.1.

Figure M.1: All 1212 possible ways for n=6n = 6.

Find the number of different ways Zack can stack nn boxes modulo 998,244,353998\\, 244\\, 353.

Two ways are considered the same if and only if the number of stacks is the same, and pairs of stacks at the same positions have the same number of boxes.

입력

The first line of input contains one integer tt (1≤t≤300,0001 ≤ t ≤ 300\\, 000) representing the number of test cases. After that, tt test cases follow. Each of them consists of a single line containing one integer nn (1≤n≤300,0001 ≤ n ≤ 300\\, 000).

출력

For each test case, output an integer representing the number of different ways to stack nn boxes modulo 998,244,353998\\, 244\\, 353.

예제1

  1. 예제 1

    입력
    4
    5
    6
    7
    890
    
    예상 출력
    7
    12
    19
    502674609