[Hihocoder] #1096: Divided Product

Source: Internet
Author: User

Time limit: 10000ms single point time limit: 1000ms memory limit: 256MB description

Given positive integers n and M, please divide N into several integers A1, A2, ..., Ak (k >= 1), so:

1.0 < A1 < A2 < ... < Ak;

2. A1 + A2 + ... + Ak = N;

3. A1, A2, ..., Ak is different with each other;

4. The product of them P = A1 * A2 * ... * Ak is a multiple of M;

How many different ways can I achieve this goal?

Input

integers n and M. 1 <= n <=, 1 <= M <= 50.

Output

Output One integer-the number of different ways to achieve this goal, module 1,000,000,007.

Sample Hints

There is 4 different ways to achieve this goal for the sample:

A1=1, a2=2, a3=4;

A1=1, a2=6;

a1=2, a2=5;

A1=3, a2=4.

Sample input
9 |
Sample output
4

Well, the question is, is it a moving rule? Think of a half-day moving rules did not want to come out, wrote a Dfs, and then incredibly passed. Think again when you are free.

1#include <iostream>2#include <vector>3#include <algorithm>4 using namespacestd;5 6typedefLong Longll;7 Constll MOD =1000000007;8 9 intN, M;Ten  One voidDFS (LL &Res, LL idx, LL Sum, LL Pro) { A     if(Sum = =N) { -         if(pro% M = =0) ++Res; -         return; the     } -      for(inti = idx +1; I <= n-sum; ++i) { -DFS (res, I, sum + i, Pro *i); -     } + } -  + voidsolve () { All res =0; atDFS (RES,0,0,1); -cout << Res <<Endl; - } -  - intMain () { -      while(Cin >> N >>M) { in solve (); -     } to}

[Hihocoder] #1096: Divided Product

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.