Zoj3662math Magic (Group backpack + full backpack)

Source: Internet
Author: User

I-Math MagicTime limit:MS Memory Limit:32768KB 64bit IO Format:%lld & Amp %llu SubmitStatus

Description

Yesterday, my teacher taught us about math: +,-, *,/, GCD, LCM ... As you know, LCM (Least Common multiple) of the positive numbers can be solved easily because of a * b = GCD (A, b) * LCM (A, B).

In class, I raised a new idea: "How to calculate the LCM of K numbers". It's also an easy problem indeed, which only cost me 1 minute to solve it. I raised my hand and told teacher about my outstanding algorithm. Teacher just smiled and smiled ...

After class, my teacher gave me a new problem and he wanted me solve it in 1 minute, too. If We know three parameters N, M, K, and both equations:

1. SUM (A1, A2, ..., Ai, ai+1,..., AK) = N
2. LCM (A1, A2, ..., Ai, ai+1,..., AK) = M

Can calculate how many kinds of solutions is there for AI (AI is all positive numbers). I began to roll cold sweat but teacher just smiled and smiled.

Can you solve this problem in 1 minute?

Input

There is multiple test cases.

Each test case contains three integers N, M, K. (1≤n, m≤1,000, 1≤k≤100)

Output

For each test case, output an integer indicating the number of solution modulo 1,000,000,007 (1e9 + 7).

You can get more details in the sample and hint below.

Sample Input

4 2 23) 2 2

Sample Output

12
Hint

The first Test case:the only solution is (2, 2).

The second Test case:the solution is (1, 2) and (2, 1).

Test instructions: There are k positive integers, and n, least common multiple m, how many combinations.

Analysis: Because this k number is the factor of M, and all the factors of M is the case of all possible least common multiple, however, n,m<=1000, so the maximum number of factors within 1000 is 35, so just record it, with the idea of discretization can be solved.

#include <stdio.h> #include <string.h>const int MOD = 1e9+7;int Dp[2][1005][1005];int lcm[1005][1005],n,m,k    , Num[105],cet;int gcd (int a,int b) {if (b==0) return A; return gcd (b,a%b);} int LCM (int a,int b) {return (A*B)/GCD (A, b);}    int main () {for (Int. i=1;i<=1000;i++) for (int j=1;j<=1000;j++) LCM[I][J]=LCM (I,J);        while (scanf ("%d%d%d", &n,&m,&k)!=eof) {cet=0;        for (int i=1;i<=m;i++) if (m%i==0) num[++cet]=i;        for (int i=0;i<=n;i++)//And for (int j=1;j<=cet;j++)//least common multiple dp[0][i][num[j]]=0;        Dp[0][0][1]=1;        int flag=0,ss,ff;            for (int k=1;k<=k;k++) {flag^=1;            for (int i=k;i<=n;i++) for (int j=1;j<=cet;j++) dp[flag][i][num[j]]=0; for (int s=k-1;s<=n;s++)//k-1 The number of at least k-1 for (int c=1;c<=cet;c++)//least common multiple {if (dp[               flag^1][s][num[c]]==0)     Continue                    for (int i=1;i<=cet;i++)//per factor {Ss=s+num[i];                    Ff=lcm[num[c]][num[i]]; if (ss>n| |                    m%ff!=0) continue;                    DP[FLAG][SS][FF]+=DP[FLAG^1][S][NUM[C]];                Dp[flag][ss][ff]%=mod;    }}} printf ("%d\n", Dp[flag][n][m]); }}


Zoj3662math Magic (Group backpack + full backpack)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.