Fair Problemset
시간 제한8초메모리 제한2048 MB
길이 3n인 수열에서 n개 난이도가 각각 세 번 등장하고, 순차 분배와 점프 분배 모두 각 난이도를 세 멤버에게 하나씩 나누도록 하는 수열의 개수를 n = 1부터 k까지 각각 소수 m으로 나눈 나머지로 구한다.
문제
This problem adopts exactly the same definition of Fair Problemset as Problem M, “Triple Fairness”.
ICPC is a team competition. Each team has three members. At the beginning of a contest, most teams divide the problem evenly. They use one of two common methods to distribute problems:
- Sequential Distribution: Each member takes a contiguous block of problems from the set of problems. Specifically, the first member takes problems , the second member takes problems , and the third member takes problems .
- Jump Distribution: Each member takes problems with indices that have the same remainder when divided by from the set of problems. Specifically, the first member takes problems , the second member takes problems , and the third member takes problems .
The ICPC Seoul Regional Contest Scientific Committee must prepare a problemset consisting of problems. The difficulty of each problem is represented by an integer from to , inclusive. For each difficulty, there are exactly three problems with that difficulty. Thus, the arrangement of difficulties in the problemset can be viewed as a difficulty sequence of length containing three problems of each of the difficulty levels.
To prevent any advantage or disadvantage for a team based on their chosen problem distribution method, the ICPC Seoul Regional Contest Scientific Committee has defined a standard called a Fair Problemset. A difficulty sequence of length is called a Fair Problemset if it satisfies both of the following conditions:
- Sequential Distribution Fairness: When using Sequential Distribution, for every difficulty level (), each of the three members receives exactly one problem with difficulty .
- Jump Distribution Fairness: When using Jump Distribution, for every difficulty level (), each of the three members receives exactly one problem with difficulty .
In other words, regardless of which of the two methods is chosen, each team member must be assigned exactly one problem for each difficulty level from to , inclusive.
Given a positive integer , write a program to find the number of Fair Problemset sequences of length for each .
입력
Your program is to read from standard input. The input consists of exactly one line. The line contains two integers, and (; ; is a prime number).
출력
Your program is to write to standard output. You should print exactly lines. On the -th line (), print the number of Fair Problemset sequences of length , modulo .
힌트
Explanation of Sample Input 2:
Here are Fair Problemset sequences of length ).