Topic 1207: Number of factorization

Source: Internet
Author: User

Topic 1207: Number of factorization

time limit:1 seconds

Memory limit:32 MB

Special question: No

submitted:7367

Resolution:2406

Title Description:
The
number of the mass factor for a positive integer N (n>1). The same quality factor requires repeated calculations. such as 120=2*2*2*3*5, a total of 5 qualitative factors.
Input:

There may be multiple sets of test data, and the input to each set of test data is a positive integer N, (1<n<10^9).

Output:

For each set of data, the number of the quality factor of the output n.

Sample input:
120
Sample output:
5
Tips:

Note: 1 is not a mass factor of N; n is the mass factor of N if n is a prime number.

#include <iostream>#include<stdio.h>#include<string.h>#include<algorithm>#include<string>using namespacestd; BOOLmark[100001];intprime[100001];intprimesize;voidInit ()//screening of all prime factors from 2 to 100000 by using prime number screening method{primesize=0;  for(intI=2; i<100000; i++)    {        if(mark[i]==true)Continue; Prime[primesize++]=i; if(i>= +)Continue;  for(intJ=i*i; j<=100000; j+=i) {mark[j]=true; }    }}intMain () {init (); intN;  while(SCANF ("%d", &n)! =EOF) {        intansprime[ -];//Save the decomposed factor in order        intAnssize=0;//decomposition of the number of factors        intansnum[ -];//the power exponent corresponding to the decomposition of the factors         for(intI=0; i<primesize; i++)//each prime number is monitored sequentially        {            if(n%prime[i]==0)//If the number can be divisible by the number of decomposition{Ansprime[anssize]=prime[i];//the factor is the vegetarian factoransnum[anssize]=0;//Initializes a power exponent of 0                 while(n%prime[i]==0)//The prime number is decomposed from the tested numbers and its power exponent is counted .{Ansnum[anssize]++; N/=Prime[i]; } anssize++;//The number of characters increases                if(n==1) Break;//if it has been decomposed into 1, the decomposition is terminated prematurely.            }        }        if(n!=1)//if all the factors within 2 to 100000 are tested, N is still not decomposed to 1, then the remaining factor must be n a factor greater than 100000{Ansprime[anssize]=n;//record the major factoransnum[anssize++]=1;//its power exponent can only be 1        }        intans=0;  for(intI=0; i<anssize; i++) {ans+=ansnum[i];//the power exponent of the statistical factors of each factor} printf ("%d\n", ans); }    return 0;} /************************************************************** problem:1207 User:zhuoyuezai language:c++ result:accepted time:10 Ms memory:2008 kb****************************************************************/

Topic 1207: Number of factorization

Related Article

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.