
ZOJ Problem Set  1570
There are n! permutations for 0, 1, 2, ..., n1. For instance n=3 we have 6 sequences 012, 021, 102, 120, 201, 210. We put the sequence in an array a. Now it's your task to tell how many of the n! sequences satisfy (a[a[b[0]]]*b[0]+a[a[b[1]]]*b[1]+a[a[b[2]]]*b[2]+a[a[b[3]]]*b[3])%n==k
There are multiple tests, terminated with end of file. Each line contains six integers, in the order n, k, b[0], b[1], b[2], b[3]. 4 <= n < 12, 0 <= k < n, 0 <= b[i] < n.
One number for each test  the number of sequences that satisfies the equation.
4 0 3 2 1 0
4
Author: ZHANG, Zheng Source: ZOJ Monthly, March 2003 