Uvalive 6073 math magic

Source: Internet
Author: User

6073 math magic
Yesterday, my teacher taught us about math: +,-, *,/, gcd, LCM... as you know, lcm (least
Common multiple) of two positive numbers can be solved easily because


A branch B = gcd (a, B) Branch 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 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 two equations:


1. sum (A1, A2,..., AI, AI + 1,..., ak) = N
2. lcm (A1, A2,..., AI, AI + 1,..., ak) = m


Can you calculate how many kinds of solutions are there for AI (AI are 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 are 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.
Hint:
The? RST test case: the only solution is (2, 2 ).
The second test case: the solution are (1, 2) AND (2, 1 ).


Sample Input
4 2 2
3 2 2


Sample output
1
2

 

1 // today is a long time to understand, tangle, read the code of the great god, only when DP 2/dp [k] [N] [m] is used to indicate the sum of K numbers n, when the minimum public multiple is m, the total number is 3 4 # include <iostream> 5 # include <cstdio> 6 # include <cstring> 7 # include <algorithm> 8 using namespace STD; 9 const int maxn = 1005; 10 const int mod = 1000000007; 11 int n, m, K; 12 int lcm [maxn] [maxn]; 13 int DP [2] [maxn] [maxn]; 14 int fact [maxn], CNT; 15 16 int gcd (int A, int B) 17 {18 return B = 0? A: gcd (B, A % B); 19} 20 21 int lcm (int A, int B) 22 {23 return a/gcd (a, B) * B; 24} 25 26 void Init () 27 {28 for (INT I = 1; I <= 1000; I ++) 29 for (Int J = 1; j <= I; j ++) 30 LCM [J] [I] = LCM [I] [J] = lcm (I, j); 31} 32 33 void solve () 34 {35 CNT = 0; 36 for (INT I = 1; I <= m; I ++) 37 If (M % I = 0) fact [CNT ++] = I; 38 39 int now = 0; 40 memset (DP [now], 0, sizeof (DP [now]); 41 for (INT I = 0; I <CNT; I ++) 42 DP [now] [fact [I] [fact [I] = 1; 43 44 for (INT I = 1; I <K; I ++) 45 {46 now ^ = 1; 47 for (INT p = 1; P <= N; P ++) 48 for (INT q = 0; q <CNT; q ++) 49 {50 DP [now] [p] [fact [Q] = 0; 51} 52 53 for (INT p = 1; P <= N; P ++) 54 {55 for (INT q = 0; q <CNT; q ++) 56 {57 if (DP [now ^ 1] [p] [fact [Q] = 0) continue; 58 for (Int J = 0; j <CNT; j ++) 59 {60 int now_sum = P + fact [J]; 61 If (now_sum> N) continue; 62 int now_lcm = LCM [fact [Q] [fact [J]; 63 DP [now] [now_sum] [now_lcm] + = DP [now ^ 1] [p] [fact [Q]; // 64 DP [now] [now_sum] [now_lcm] % = MOD; // 65} 66} 67} 68} 69 printf ("% d \ n ", DP [now] [N] [m]); 70} 71 72 int main () 73 {74 Init (); 75 while (scanf ("% d", & N, & M, & K)> 0) 76 solve (); 77 return 0; 78}

 

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.