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