UVA 10699 Count The Factors







#include <bits/stdc++.h>
using namespace std;

long long int primefactors(long long int n)
{

    long long int c=0,p=0,d=0;

    while(n%2==0)
    {
        c++;
        if(c==1)
        {
            d++;
        }
        n=n/2;
    }
    for(int i=3;i<=sqrt(n);i=i+2)
    {
        while(n%i==0)
        {
            if(p!=i)
            {
                d++;
            }
            p=i;
            n=n/i;
        }

    }
    if(n>2)
    {
        d++;
    }
    return d;
}

int main()
{
    long long int n;
    while(cin>>n)
    {
        if(n==0)
        {
            break;
        }
       printf("%lld : %lld\n",n,primefactors(n));

    }
    return 0;
}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment