atcoder#AGC052C. [AGC052C] Nondivisible Prefix Sums
[AGC052C] Nondivisible Prefix Sums
Score : points
Problem Statement
You are given a prime number , which you don't like.
Let's call an array of integers good, if it is possible to reorder the elements in such a way that no prefix sum is divisible by (that is, there is no with and after the reordering).
Consider all arrays of length with elements from to . How many of them are good?
As this number can be very big, output it modulo .
Constraints
- is a prime.
Input
Input is given from Standard Input in the following format:
Output
Output the number of good arrays modulo .
2 5
12
There are good arrays: , , , , , , , , , , , .
4 3
8
There are good arrays: , , , , ], , , .
5000 99999989
51699346
2021 307
644635349