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

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 &g...

Powered by Blogger.