Fortune Telling

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

요약
주사위를 굴려 나온 수 x에 따라 x번째 카드부터 6칸 간격으로 제거하는 과정을 카드가 하나 남을 때까지 반복할 때, 각 위치의 카드가 마지막까지 남을 확률을 모듈러로 구한다.
난이도

어려움10점 중 8점

유형
확률, 동적 계획법, 수학, 시뮬레이션
정답자
아직 제출이 없습니다

문제

Your fortune is to be told by a famous fortune teller. She has a number of tarot cards and a six-sided die. Using the die, she will choose one card as follows and that card shall tell your future.

Initially, the cards are lined up in a row from left to right. The die is thrown showing up one of the numbers from one through six with equal probability. When xx is the number the die shows up, the xx-th card from the left and every sixth card following it, i.e., the (x+6k)(x + 6k)-th cards for k=0,1,2,…k = 0, 1, 2, \dots, are removed and then remaining cards are slid left to eliminate the gaps. Note that if the number of cards remaining is less than xx, no cards are removed. This removing and sliding procedure is repeated until only one card remains.

Figure G.1 illustrates how cards are removed and slid when the die shows up two.

Figure G.1. Removing and sliding cards

You are given the number of initial tarot cards. For each card initially placed, compute the probability that the card will remain in the end.

입력

The input is a single line containing an integer nn, indicating the number of tarot cards, which is between 22 and 3×1053 \times 10^5, inclusive.

출력

Output nn lines, the ii-th of which should be an integer that is determined, as follows, by the probability of the ii-th card from the left to remain in the end.

It can be proved that the probability is represented as an irreducible fraction a/ba/b, where bb is not divisible by a prime number 998,244,353=223×7×17+1998\\, 244\\, 353 = 2^{23} \times 7 \times 17 + 1. There exists a unique integer cc such that bc≡a(mod998,244,353)bc \equiv a \pmod {998\\, 244\\, 353} and 0≤c<998,244,3530 ≤ c < 998\\, 244\\, 353. What should be output is this integer cc.

힌트

For Sample Input 1, the probabilities to remain in the end for all the cards are equal, that are 1/31/3.

For Sample Input 2, let us consider the probability of the leftmost card to remain in the end. To make this happen, the first number the die shows up should not be one. After getting a number other than one, six cards will remain. Each of these six cards will remain in the end with the same probability. From this observation, the probability of the leftmost card to remain in the end is computed as (5/6)×(1/6)=5/36(5/6) \times (1/6) = 5/36. The same argument holds for the rightmost card. As for the rest of the cards, the probabilities are equal, and they are (1−2×5/36)/5=13/90(1 - 2 \times 5/36)/5 = 13/90.

예제3

  1. 예제 1

    입력
    3
    
    예상 출력
    332748118
    332748118
    332748118
    
  2. 예제 2

    입력
    7
    
    예상 출력
    305019108
    876236710
    876236710
    876236710
    876236710
    876236710
    305019108
    
  3. 예제 3

    입력
    8
    
    예상 출력
    64701023
    112764640
    160828257
    160828257
    160828257
    160828257
    112764640
    64701023