Factor and number of factors

Source: Internet
Author: User

1. Number of factors for n

Condition: Given any one positive integer n

Requirements: Number of factors to be evaluated

First, the conclusion: for arbitrary integral type N, decomposition factorization get n= p1^x1 * p2^x2* ... * PN^XN;

n the number of factors M is m= (x1+1) * (x2+1) * ... * (xn+1);

Proof Process:

Let me give you an example.

24 = 2^3 * 3^1;

The qualitative factors are: the 2 and 3 indices are 3 and 1

So for 2 there are 0 1 2 34 kinds of index choices, for 3 there are 0 12 kinds of index selection

So that's 4 * 2 = 8 factor number

If you still don't understand, then let's list it.

2 3

2^0*3^0=1 2^0*3^1=3

2^1*3^0=2 2^1*3^1=6

2^2*3^0=4 2^2*3^1=12

2^3*3^0=8 2^3*3^1=24

The results are clear, right? Actually, the knowledge of mathematical permutations is used here.

That is to say, the different exponential powers of each mass factor are multiplied by the other mass factors, and the resulting results must not be repeated.

So it is possible to enumerate all the factors.

So n the number of factors m, we can use m= (x1+1) * (x2+1) * ... * (xn+1) to indicate

2. How to find the number of a factor in n!

2. N! Number of factors

With the above conclusion, the problem becomes more clear. Hey, don't worry, there are a lot of details that we need to consider.

A. the maximum quality factor must not be greater than n

B. the mass factor of n does not completely contain n! All the quality factors

As to what the reason is, think about it, hey.

So let's just say the idea:

First, we can make a list of all the prime numbers within N.

Then, for each of the index number of qualitative factors, here is used to a formula:

ei=[n/pi^1]+ [n/pi^2]+ ... + [n/pi^n] where [] is rounding

attached: This step has recently thought of a better way int ei=0;while (N) ei+= (N/=PI); How's that? ?

(think about why, I really don't think you can give an example to try)

Finally, the set of formulas calculated, m= (e1+1) * (e2+1) *......* (en+1)

Well, let's just give an example.

Like 5!

The index of the mass factor 2 is 2+1=3;

The index of the mass factor 3 is 1;

The index of the mass factor 5 is 1;

So the number of factors is 4 * 2 * 2 = 16

5! The =120 factor is 1 2 3 4 5 6 8, and the 4060

Reproduced in: http://www.cnblogs.com/dolphin0520/archive/2011/04/11/2012891.html

To find the factorial of n a factor a number, if n is relatively small, can be directly calculated, but if n is very large, at this time n! beyond the scope of the data, this method of direct seeking is certainly not feasible. In fact, n! can be expressed as a unified way.

n!= (k^m) * (m!) *a where k is the factor and M=n/k,a is the product of the number without factor K

This formula is deduced below

n!=n* (n-1) * (n-2) * ... 3*2*1

= (K*2K*3K.....*MK) *a A is the product of the number without factor K, obviously m=n/k;

= (k^m) * (1*2*3...*m) *a

=k^m*m!*a

Next, the same method can be used to find out the number of factor k in m!.

So we can find out the number of factor K in n!

int count (int n,int  k) {    int num=0;      while (n)    {        num+=n/k;        n/=k;    }     return num;}

3. Number of product factors for a given series

In fact, this is also based on the first conclusion obtained.

Given A1 A2 A3 ... an;

We can find the largest element of Max (a);

Make a list of the primes within Max

Then the quality factor is cleared, and the following loops can be used to find the number of each mass factor:

for (a=1;a<=n;a++)

for (p=1;p<_;p++)

if (__) e (P) + +;

The qualitative number of the qualitative factor is calculated, and then the number of factors can be calculated according to the formula m= (e1+1) * (e2+1) *......* (en+1)

Factor and number of factors

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.