F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Problem D. Permutation

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 240    Accepted Submission(s): 89


Problem Description
Define the value of a permutation of 1 . . . n as
n
¡Æ|pi - i|
i=1

Given n, p, for every s = 0 . . . n^2-1, count the number of permutations of length n
whose value equals to s.
Output the answer modulo a prime p.
 

Input
The first line of the input contains an integer T , denoting the number of test cases.
In each test case, there are two integers n, p in one line, denoting the length of permutations and the modulo.
1 ¡Ü T ¡Ü 10, 1 ¡Ü n ¡Ü 100, 10^9 < p < 1.1 ¡Á 10^9, only two cases¡¯ n > 50, p is a prime.
 

Output
For each test case, output one line contains n^2 integer, denoting the number of permutations of length n whose value equals to s = 0 . . . n^2-1 modulo p.
 

Sample Input
4 4 1000000223 3 1000000321 2 1000000123 1 1000000447
 

Sample Output
1 0 3 0 7 0 9 0 4 0 0 0 0 0 0 0 1 0 2 0 3 0 0 0 0 1 0 1 0 1
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-30 04:07:12, Gzip enabled