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
2 3 4 10 100
Sample Output
1 1 1 1 2 1 2 2 4 6
題意:給你一個數X,將X分解成1~X的因子數列,前一個數可以整數後一個數,求滿足條件的最大鏈長以及有多少條這樣長的鏈。
分析:很容易想到了素因數分解。不難推出,我們要求的最大鏈長就等於素因子的個數,最長鏈條數就是這些素因子的排列組合數。題目數據量較大,所以先打個素數表。
題目鏈接:http://poj.org/problem?id=3421
代碼清單:
#include#include