Single point time limit: 1000ms
Memory Limit: 256MB
Describe
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 input
7 2
Sample output
4
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.
The idea is violence, try all the things.
#include <iostream>using namespace STD;typedef unsigned Long LongUll;ull N, M;ull r =0;Constull MOD =1000000007;voidDFS (ull i, ull s, ull p) {if(s = = N) {if(p% M = =0) r++;return; } for(Ull j = i +1; J < N-S +1; J + +) {Dfs (J, S + J, p * j); }}intMain () {Cin>> N >> M; DFS (0,0,1);cout<< r% MOD << Endl;return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Integer partitioning Problem--dfs