携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第5天,点击查看活动详情
Mashmokh and ACM
题面翻译
如果一个数列中,后一个数都能被前面一个数整除,那么就叫这个数列为好数列。输入 ,求数列中最大元素不超过 ,数列长度为 的好数列的种数(对 取模)
由 @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 integers is called good if each number divides (without a remainder) by the next number in the sequence. More formally for all .
Given and find the number of good sequences of length . As the answer can be rather large print it modulo .
输入格式
The first line of input contains two space-separated integers .
输出格式
Output a single integer — the number of good sequences of length modulo .
样例 #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: .
#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;
}