Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
1.1 kB
4
Indexable
Never
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

const int MOD = 1e9 + 7;

vector<pair<long long, long long>> findPairs(long long M) {
    vector<pair<long long, long long>> pairs;
    for (long long x = 1; x <= sqrt(M); ++x) {
        if (M % x == 0) {
            long long y = M / x;
            pairs.push_back({x, y});
            if (x != y) {
                pairs.push_back({y, x});
            }
        }
    }
    return pairs;
}

int main() {
    long long N, M;
    int K;
    cin >> N >> M >> K;
    K = min(M, 50LL); // Ensure K is at most 50

    vector<pair<long long, long long>> pairs = findPairs(M);

    vector<vector<long long>> dp(N + 1, vector<long long>(K + 1, 0));
    dp[0][0] = 1;

    for (long long i = 1; i < N; ++i) {
        for (int j = 0; j <= K; ++j) {
            for (auto &p : pairs) {
                if (j > 0) {
                    dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % MOD;
                }
                dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
            }
        }
    }

    cout << dp[N-1][K] << endl;
    return 0;
}
Leave a Comment