Codeforces 26 A. Almost Prime Solution
Solution in C++:
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd Batch
///Islamic University,Bangladesh
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int primefactor(int n)
{
int i,c=0;
for(int i=2; i<=sqrt(n); i++)
{
if(n%i==0)
{
while(n%i==0)
{
n=n/i;
}
c++;
}
}
if(n!=1)
c++;
return c;
}
int main()
{
int a,c,i,n,r=0,t=0;
cin>>a;
for(i=2; i<=a; i++)
{
r=primefactor(i);
if(r==2)
t++;
}
cout<<t<<endl;
}
///**********ALLAH IS ALMIGHTY************///
///AH Tonmoy
///Department of CSE,23rd Batch
///Islamic University,Bangladesh
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int primefactor(int n)
{
int i,c=0;
for(int i=2; i<=sqrt(n); i++)
{
if(n%i==0)
{
while(n%i==0)
{
n=n/i;
}
c++;
}
}
if(n!=1)
c++;
return c;
}
int main()
{
int a,c,i,n,r=0,t=0;
cin>>a;
for(i=2; i<=a; i++)
{
r=primefactor(i);
if(r==2)
t++;
}
cout<<t<<endl;
}
No comments