题意:
Description
Given a positive integer X, an X-factor chain of length m is a sequence of integers,
1 = X0, X1, X2, …, Xm = X
satisfying
Xi < Xi+1 and Xi | Xi+1 where a | b means a perfectly divides into b.
Now we are interested in the maximum length of X-factor chains and the number of chains of such length.
Input
The input consists of several test cases. Each contains a positive integer X (X ≤ 220).
Output
For each test case, output the maximum length and the number of such X-factors chains.
Sample Input
23410100
Sample Output
1 11 12 12 24 6
思路:
一开始想到dp。令dp[i][j]表示长度为i,以j结尾的链的个数,于是dp[i+1][k] += dp[i][j] (j为k的因子),然而复杂度高,并不会优化。
后来发现要想链最长,只能从1开始,每次乘上这个数的某个质因子才行。于是就变成了分解质因子+排列组合的问题。
实现:
1 #include2 #include 3 #include 4 #include 5 #include 6 #include