POJ_3421_X-factor Chains (prime screening method)

Source: Internet
Author: User

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
             
              

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.