Counting permutations
Practice
2.8 (6 votes)
Special numbers
Counting
Mathamatics
Math
C++
Problem
61% Success 751 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given two integers \(n\) and \(m\). You are required to find the number of permutations of \(n\) such that for each \(i\) the \(|a_i - i| ≠ m\) where \(|x - y|\) denotes the absolute difference between \(x\) and \(y\).

Example:

Here, \(n = 4\) and \(m = 3\), therefore, the valid permutations are \([2\ 4\ 1\ 3]\), \([1\ 3\ 4\ 2]\), and so on. The invalid permutations for the same are \([4\ 1\ 3\ 2]\), \([3\ 2\ 4\ 1]\), and so on.

Note: As the number can be large, print answer modulo \(1000000007\).

Input format

The first line contains two integers \(n\) and \(m\).

Output format

Print one integer denoting the number of permutations that are valid. As the number can be very large, print answer modulo \(1000000007\).

Constraints

 \(2 ≤ n ≤ 1e3\\ 1 ≤ m < n\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
Tags:
Medium-Hard
Editorial

Login to unlock the editorial