-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrintFactor.h
More file actions
43 lines (35 loc) · 881 Bytes
/
PrintFactor.h
File metadata and controls
43 lines (35 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
bluepp
2014-12-25
May the force be with me!
http://www.mitbbs.com/article_t1/JobHunting/32803907_0_1.html
打印一个数的所有乘数组合,从大到小,不要有重复
24=2*2*2*3
=2*3*4
=2*12
=3*8
=4*6
*/
vector<vector<int> > printfactor(int n)
{
vector<int> vec;
vector<vector<int> >res;
_factor(n, n/2, vec, res);
return res;
}
vector<vector<int> > _factor(int n, int start, vector<int> &vec, vector<vector<int> &res)
{
if (n == 1)
{
res.push_back(vec);
return;
}
for (int i = start; i <= n; i++)
{
if (n % i) continue;
vec.push_back(i);
//_factor(n/i, i, vec, res);
_factor(n/i, min(i, n/i), vec, res);
vec.pop_back();
}
}