题库练习 Maximum Element
← 上一题 下一题 →

A11434 | Maximum Element

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

One day Petya was solving a very interesting problem. But although he used many optimization techniques, his solution still got Time limit exceeded verdict. Petya conducted a thorough analysis of his program and found out that his function for finding maximum element in an array of $n$ positive integers was too slow. Desperate, Petya decided to use a somewhat unexpected optimization using parameter $k$ , so now his function contains the following code:

<br></br>int fast_max(int n, int a[]) { <br></br> int ans = 0;<br></br> int offset = 0;<br></br> for (int i = 0; i < n; ++i)<br></br> if (ans < a[i]) {<br></br> ans = a[i];<br></br> offset = 0;<br></br> } else {<br></br> offset = offset + 1;<br></br> if (offset == k)<br></br> return ans;<br></br> }<br></br> return ans;<br></br>}<br></br>That way the function iteratively checks array elements, storing the intermediate maximum, and if after $k$ consecutive iterations that maximum has not changed, it is returned as the answer.

Now Petya is interested in fault rate of his function. He asked you to find the number of permutations of integers from $1$ to $n$ such that the return value of his function on those permutations is not equal to $n$ . Since this number could be very big, output the answer modulo $10^{9}+7$ .

输入格式

The only line contains two integers $n$ and $k$ ( $1<=n,k<=10^{6}$ ), separated by a space — the length of the permutations and the parameter $k$ .

输出格式

Output the answer to the problem modulo $10^{9}+7$ .

输入输出样例

输入 #1
5 2
输出 #1
22
输入 #2
5 3
输出 #2
6
输入 #3
6 3
输出 #3
84
C++ 编辑器
输入
输出