Mashmokh’s boss, Bimokh, didn’t like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh’s team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced programmer. Actually he is not a programmer at all. So he wasn’t able to solve them. That’s why he asked you to help him with these tasks. One of these tasks is the following.
A sequence of l integers b1, b2, …, bl (1 ≤ b1 ≤ b2 ≤ … ≤ bl ≤ n) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all i (1 ≤ i ≤ l - 1).
Given n and k find the number of good sequences of length k. As the answer can be rather large print it modulo 1000000007 (109 + 7).
Input
The first line of input contains two space-separated integers n, k (1 ≤ n, k ≤ 2000).
Output
Output a single integer — the number of good sequences of length k modulo 1000000007 (109 + 7).
如果一个数列中,后一个数都能被前面一个数整除,那么就叫这个数列为好数列。输入n,k,求数列中最大元素为n,数列长度为k的好数列的种数(对1000000007取模)
题解:类似(埃式筛法)
那么首先设计状态,用dp[i][j]来表示长度为i,末位数字为k的情况下,能够达到的最优解。
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 2005; int dp[maxn][maxn]; int main() { int n, m; cin >> n >> m; dp[0][1] = 1; for (int i = 0; i <= m; i++) { for (int j = 1; j <= n; j++) { for (int k = j; k <= n; k += j) { dp[i + 1][k] = (dp[i + 1][k] + dp[i][j]) % mod; } } } int ans = 0; for (int i = 1; i <= n; i++) { ans = (ans + dp[m][i]) % mod; } cout << ans << endl; return 0; }