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 925 (Div. 3) 1931D. Divisible Pairs Solution

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

Powered by Blogger.