Beautiful Permutations
InterviewTime limit1sMemory limit1024 MB
Given n and k, count the permutations of 1 to n whose sum of adjacent products is divisible by k.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Bit manipulation, Brute force
- Solved
- No attempts yet
Statement
A permutation of size is an array of distinct integers from to . Each number appears in the permutation exactly once.
Senya calls the beauty of a permutation the value . He wants to count the permutations whose beauty is divisible by .
Given and , find the number of permutations of size whose beauty is divisible by .
Input
Two integers and are given (, ).
Output
Print one integer: the number of permutations of size whose beauty is divisible by .