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;
}
///**********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