[Simulation 10.31 Race] T3

Description

There are green grassland \ (k \) sheep, they gathered at the home of an adult bag, held the annual awards ceremony, this time in the awards ceremony, the bags allow adults to pursue their own sheep contribution from small to large in a row, so that bonuses.
Values are obtained each sheep \ (. 1 \) ~ \ (n-\) prize, and a bonus to be the i-th sheep for the first \ (i + 1 \) about the number of sheep (i.e. satisfies \ (AI | +. 1 AI \) ).
Now a bag of adults would like to know how many different ways there are bonuses (bonuses are two ways to refer to different ways of different bonuses exist in both the sheep get a bonus)

Input

Line two positive integers \ (n-\) , \ (K \) , satisfying ( \ (. 1 <= n-\) , \ (K <= 1000000 \) )

Output

Program on behalf of his party to an integer bonuses (1000000007 \) \ result modulo

Sample Input

6 4

Sample Output

3 9

Data Constraint

For (20 \) \ % Data: \ (n-, K <= 10 \)
to (50 \) \ % Data: \ (n-, K <= 2000 \)
to \ (100 \) data percent: \ (n, k <= 1000000 \)

Limit

\(2000ms\) \(512M\)

Solution

The first may assume \ (I \) sheep obtained for the bonus \ (AI \) , then the \ (A \) the number of different sequence number does not exceed \ (O (logn) \) all numbers, and ascending arrangement, it is possible to enumerate \ (a \) the number of different sequence numbers \ (D \) , it may be assumed these different numbers are \ (P1 \) , \ (P2 \) , \ (P3 \) ... \ (PD \) , considering statistical \ (P \) the number of sequence: with \ (f [i] [j ] \) represents the length of \ (I \) and \ (pi = j \) of \ (P \) sequence number, a \ (f [i + 1] [t * j] + = f [i] [j] \) is updated to.
Then \ (cnt [i] = \ sum f [i] [j] \) is the length \ (I \) a \ (\ P) number sequence.
Next, consider obtaining \ (p1 \) ,\ (P2 \) , \ (P3 \) ... \ (PD \) into \ (A \) the number of program sequences, the method can be determined by the number of the separator scheme \ (C (k-1 ,. 1-D) \) , and thus the total number of programs for
\ (\ sum ^ {logk} _ {i = 1} cnt [d] \ ast C (k-1, d-1) \)

Code

#include<iostream>
#include<cstdio>
using namespace std;
#define ll long long
#define MOD 1000000007
#define N 1000020
#define M 22
#define MAXN 10010
ll n, k, ans;
ll H[N], f[M][N], cnt[M];
inline ll read() {
    ll s = 0, w = 1;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') w = -1;
    for (; isdigit(c); c = getchar()) s = (s << 1) + (s << 3) + (c ^ 48);
    return s * w;
}
inline ll Pow(ll a, ll k) {
    ll ans = 1;
    while (k) {
        if (k & 1) (ans *= a) %= MOD;
        (a *= a) %= MOD;
        k >>= 1;
    }
    return ans;
}
inline ll Inv(int a) {
    return Pow(a, MOD - 2);
}
inline void Init() {
    H[0] = 1;
    for (register int i = 1; i <= N; i++)
        H[i] = (H[i - 1] * i) % MOD;
}
inline ll C(ll x, ll y) {
    return H[x] * Inv(H[y]) % MOD * Inv(H[x - y]) % MOD;
}
int main() {
    freopen("commend.in", "r", stdin);
    freopen("commend.out", "w", stdout);
    Init();
    n = read(), k = read();
    for (register int i = 1; i <= n; i++)
        f[1][i] = 1;
    for (register int i = 1; i < M - 1; i++)
        for (register int j = 1; j <= n; j++)
            for (register int k = j + j; k <= n; k += j)
                (f[i + 1][k] += f[i][j]) %= MOD;
    for (register int i = 1; i < M; i++)
        for (register int j = 1; j <= n; j++)
            (cnt[i] += f[i][j]) %= MOD;
    for (register int i = 1; i <= k && i < M; i++)
        (ans += cnt[i] * C(k - 1, i - 1) % MOD) %= MOD;
    cout << ans;
    return 0;
}

Guess you like

Origin www.cnblogs.com/Agakiss/p/11779203.html