POJ_3421_X-factor Chains (prime screening method)
X-factor Chains
Time Limit:1000 MS |
|
Memory Limit:65536 K |
Total Submissions:5659 |
|
Accepted:1786 |
Description
Given a positive integerX,X-Factor chain of lengthMIs a sequence of integers,
1 =X0,X1,X2 ,...,Xm=X
Satisfying
Xi<Xi+ 1 andXi|Xi+ 1 whereA|BMeansAPerfectly dividesB.
Now we are interested in the maximum lengthX-Factor chains and the number of chains of such length.
Input
The input consists of several test cases. Each contains a positive integerX(X≤ 220 ).
Output
For each test case, output the maximum length and the number of suchX-Factors chains.
Sample Input
23410100
Sample Output
1 11 12 12 24 6
Question: Give You A number X and divide X into 1 ~ The number of factor columns of X. The previous number can be an integer and the next number, and the maximum chain length that meets the conditions and the number of such long chains can be obtained.
Analysis: it is easy to think of prime factor decomposition. It is not difficult to introduce that the maximum chain length we require is equal to the number of prime factors, and the maximum number of chains is the number of arrangement and combination of these prime factors. The data volume of the question is large, so first create a prime number table.
Question link: http://poj.org/problem? Id = 3421
Code List:
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Includeusing namespace std; typedef long ll; typedef unsigned long ull; typedef unsigned int uint; const int maxp = 10000 + 5; const int maxn = 1100000 + 5; int sum, x; int prime [maxp]; bool vis [maxn]; int num [maxp], k; // store the number of each prime factor void init () {// The sum = 0; memset (vis, true, sizeof (vis); for (int I = 2; I <= maxn; I ++) {if (! Vis [I]) continue; prime [sum ++] = I; if (I> (int) sqrt (maxn) continue; for (int j = I * I; j <= maxn; j + = I) vis [j] = false;} ll get_max () {// obtain the maximum chain length, that is, the number of prime factors ll ans = 0; for (int I = 0; I