UVA 10699 Count the factors Solution

Solution in c++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
#include<iostream>
#include<set>
#include<math.h>
using namespace std;
set<int>s;
void pf(int n)
{
    cout<<n<<" : ";
    while(n%2==0)
    {
        s.insert(2);
        n=n/2;
    }
    for(int i=3; i<=sqrt(n); i=i+2)
    {
        while(n%i==0)
        {
            s.insert(i);
            n/=i;
        }
    }
    if(n>1)
    {
       s.insert(n);
    }

}
int main()
{
    int n,si;
    while(cin>>n)
    {
        if(n==0)
            break;
        pf(n);
        si=s.size();
        cout<<si<<endl;
        s.clear();

    }

    return 0;
}

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.