HDU 1299 prime number filtering + factor count

Source: Internet
Author: User

It is easy to calculate the number of factors. Calculate the number of each qualitative factor, and then combine the mathematical solutions.

The following is an online download... I thought it was all written in this way...

  1. /*************************************** ***********
  2. First, we know that X and Y are all numbers greater than N.
  3. Suppose y = N + K (k> = 1)
  4. Take 1/x + 1/y = 1/N and obtain x = N * (N + k)/K-> X = n ^ 2/K + n
  5. X is an integer, so we only need to know the number of K whose N * n/K is an integer (K is definitely less than N)
  6. That is, the number of factors in N * n ....
  7. Each number can be divided into n = p1 ^ E1 * P2 ^ e2 * P3 ^ E3. PR ^ er P1.... PR is a prime number smaller than N.
  8. The number of factors is num = (1 + E1) * (1 + e2) * (1 + E3) *... * (1 + Er)
  9. So the number of N * n factors is CNT = (1 + 2 * E1) * (1 + 2 * E2) *... * (1 + 2 * er)
  10. **************************************** ***********/

 

/*

To be honest, this question is very good. You must learn to translate it into a mathematical question to explain it ..

*/

# Include <iostream>
# Include <cmath>
Using namespace STD;
# Define Manx 100000
Bool s [Manx];
Int P [Manx], num;
Int prime (){
For (INT I = 0; I <= Manx; I ++)
S [I] = 0;
For (INT I = 2; I <= (INT) SQRT (double) Manx); I ++ ){
If (! S [I]) {
For (Int J = 2; j * I <= Manx; j ++)
S [I * j] = 1;
}
}
Num = 1;
For (INT I = 2; I <Manx; I ++)
If (! S [I]) P [num ++] = I;
}
Int main (){
Prime ();
Int t, n, x [500]; // Number of retention quality factors
Scanf ("% d", & T );
For (int ii = 1; II <= T; II ++ ){
Scanf ("% d", & N );
Memset (x, 0, sizeof (x ));
Int flag = 0;
For (INT I = 1; I <num & P [I] <= N; I ++ ){
Int J = 0;
While (N % P [I] = 0) {// calculate the number of each Prime Factor
X [flag] ++;
N/= P [I];
J = 1;
}
If (j) Flag ++;
}
Int sum = 1;
For (INT I = 0; I <flag; I ++) {// calculate the number of N * n Factors
Sum * = (X [I] * 2 + 1 );
}
If (n> 1) sum * = 3; // This n must be a prime number and must be calculated ..
Printf ("Scenario # % d: \ n", ii );
Printf ("% d \ n", sum/2 + 1 );
}
}

 

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.