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;
integers n and M. 1 <= n <=, 1 <= M <= 50.
Output One integer-the number of different ways to achieve this goal, module 1,000,000,007.
A1=3, a2=4.
4
#include <iostream>using namespace Std;int n=0;//function for printing (output)//result an array that stores the result of a partition, length of this division is 1 (starting from 0) void Display (int *result,int length) {for (int i=0;i<length;i++) cout<<result[i]<< ""; Cout<<endl;} BOOL Norepeat (int *result,int length) {int a[1000]={0};for (int i=0;i<length;i++) {if (a[result[i]]!=0) {return false;} else{a[result[i]]++;}} return true;} BOOL Ismultipleright (int *result,int length,int m) {int a=1;for (int i=0;i<length;i++) {a*=result[i];} if (a%m = = 0) {return true;} return false;} The main partition function q (int n,int m,int *result,int length)//n is the integer to be divided, M is the maximum addend upper limit, result and length mean to be in the same display function//The q is divided into five case class discussion, which contains recursive call int Q (int n,int m,int *result,int length,int multiple) {//when n>=1 and M=1, Q (n,m,result,length) =q (n-1,m,result,length) if (n >=0&&m==1) {//until n=0 and m=1, output I F (n==0) {display (result,length), if (Norepeat (result,length) &&ismultipleright (result,length,multiple)) {N+ +;}} Else{resUlt[length]=1;q (n-1,m,result,length+1,multiple);} return 1;} When N=1 and m>1, the decomposition is complete, output else if (n==1&&m>1) {Result[length]=n;display (Result , length+1); if (Norepeat (result,length) &&ismultipleright (result,length,multiple)) {N++;} return 1;} When N<m, Q (n,m,result,length) =q (n,n,result,length) Else if (n<m) {return Q (n,n, Result,length,multiple);} When N=m, Q (n,m,result,length) =q (n,m-1,result,length) +1 (number of divisions) else if (n==m) {result[l Ength]=m;display (result,length+1); if (Norepeat (result,length) &&ismultipleright (result,length,multiple)) {n++;} return Q (n,m-1,result,length,multiple) +1;} When N>m>1,//q (n,m,result,length) =q (n-m,m,result,length+1) +q (n,m-1,result,length) Else {result[length]=m; return Q (n-m,m,result,length+1,multiple) +q (n,m-1,result,length,multiple);}} int main () {int n,m; int result[100]={0},length=0; cout<< "Please input the integer:"; cin>>n>>m; cout<< the number of "integers" <<n<< "<<q" (n,n,result,length,m) <<endl; cout<< "The number of qualified division is" <<N<<endl; return 0; }