【8月刷题打卡】 Mashmokh and ACM

125 阅读2分钟

携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第5天,点击查看活动详情

Mashmokh and ACM

题面翻译

如果一个数列中,后一个数都能被前面一个数整除,那么就叫这个数列为好数列。输入 n,kn, k,求数列中最大元素不超过 nn,数列长度为 kk 的好数列的种数(对 10000000071000000007 取模)

由 @ROBOT233 提供翻译

题目描述

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 ll integers b1,b2,...,blb_{1},b_{2},...,b_{l} (1<=b1<=b2<=...<=bl<=n)(1<=b_{1}<=b_{2}<=...<=b_{l}<=n) is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all ii (1<=i<=l1)(1<=i<=l-1) .

Given nn and kk find the number of good sequences of length kk . As the answer can be rather large print it modulo 10000000071000000007 (109+7)(10^{9}+7) .

输入格式

The first line of input contains two space-separated integers n,k (1<=n,k<=2000)n,k (1<=n,k<=2000) .

输出格式

Output a single integer — the number of good sequences of length kk modulo 10000000071000000007 (109+7)(10^{9}+7) .

样例 #1

样例输入 #1

3 2

样例输出 #1

5

样例 #2

样例输入 #2

6 4

样例输出 #2

39

样例 #3

样例输入 #3

2 1

样例输出 #3

2

提示

In the first sample the good sequences are: [1,1],[2,2],[3,3],[1,2],[1,3][1,1],[2,2],[3,3],[1,2],[1,3] .

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2005, mod = 1e9+7;

ll n, k;
ll dp[N], tmp[N], ans;

int main() {
	scanf("%lld%lld", &n, &k);
	for(ll i=1;i<=n;i++) dp[i] = 1;
	for(ll cnts=2;cnts<=k;cnts++) {
		for(ll i=1;i<=n;i++) tmp[i] = 0;
		for(ll i=1;i<=n;i++) {
			for(ll j=1,_=i*j;_<=n;j++,_=i*j) tmp[_] = (tmp[_] + dp[i]) % mod;
		}
		for(ll i=1;i<=n;i++) dp[i] = tmp[i];
	}
	for(ll i=1;i<=n;i++) ans = (ans + dp[i]) % mod;
	printf("%lld\n", ans);
	return 0;
}