The problem of the number of factors of a factor

Source: Internet
Author: User

Types of vegetarian factors:

For an n, what is his total number of elements? Facebook Hackercup Round1 Homework question, 10pts


Use Sieve method, then p[j]=i->p[j]++


int getprimefactortypetimes (int n) {    memset (p, 0, sizeof p);    for (int i=2;2*i<=n;i++)    {        if (! P[i])        {for            (int j=2*i;j<=n;j+=i) p[j]++;        }    }    return p[n];}



Types of vegetarian factors:


For a n, what is the total number of his factors? Codeforces Http://codeforces.com/contest/546/problem/D


The first sieve method to calculate a factor of each j, as long as any one on the line, and then DP, using the idea of divided treatment, solve the sub-problem, and then push it up just fine


LL DP[MAXN], P[MAXN], SUM[MAXN], N, T, M, A, b;void Init () {    memset (p, 0, sizeof p);    P[1]=1;    for (LL i=2;i*i<=maxn;i++)    {        if (! P[i])        {for            (LL j=i*i;j<=maxn;j+=i)                p[j]=i;        }    }    Dp[1]=dp[2]=dp[3]=1;for (LL i=2;i<=maxn;i++) dp[i]= (P[i]? (dp[i/p[i]]+1): 1); Sum[0]=0;for (LL i=1;i<=maxn;i++) sum[i]=sum[i-1]+dp[i];} int main () {/* #ifndef Online_judge    freopen ("In.txt", "R", stdin);    Freopen ("OUT.txt", "w", stdout); #endif */    Init ();    T=getint ();    for (int ti=1;ti<=t;ti++)    {        a=getint (), B=getint ();p rintf ("%d\n", Sum[a]-sum[b]);    } return 0;}

What is the number of calculation factors?

Brute force enumeration, decomposition from 1->SQRT (n), or mass factor, and then each power +1 multiplicative.

File end flag Eof,windows Ctrl + Z is the end, Linux is just-1, which represents a return value of the function


The problem of the number of factors of a factor

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.