#SP0000232. Xác suất nhận được tích N qua xúc xắc (Dice Product 3)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Xác suất nhận được tích N qua xúc xắc (Dice Product 3)
Dice Product 3
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Initially you hold the integer and have a fair six-sided die numbered from through . While , roll the die; if it shows , replace by . The process stops once . A roll of does not change but is still a legitimate outcome.
Find the probability that the final value equals exactly , modulo .
Precisely, if the probability in lowest terms is , print the unique integer in satisfying . Existence and uniqueness are guaranteed by the constraints.
Input
The only line contains an integer .
Output
Print the integer representing the probability that the final integer equals , modulo .
Subtasks
-
Subtask 1 (20 points): .
-
Subtask 2 (30 points): .
-
Subtask 3 (50 points): .
Examples
Input
6
Output
239578645
Explanation
For , stopping at can occur by rolling directly, or by first reaching then rolling , or first reaching then rolling . Rolls of leave the current value unchanged and must be accounted for as repeated attempts. Summing the valid paths including such repetitions yields probability . Since , the required output is .