-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAlmostPrime.cpp
54 lines (42 loc) · 1018 Bytes
/
AlmostPrime.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
// Kevin Mathew T
// Birla Institute of Technology, Mesra
// GitHub - https://github.com/KevinMathewT
// CodeForces - https://codeforces.com/profile/KevinMathew
// CodeChef - https://www.codechef.com/users/KevinMathew
// HackerRank - https://www.hackerrank.com/KevinMathew?
ll n, sieve[4000], pfact[4000];
void solve(){
cin >> n;
for(ll i=0;i<4000;i++)
sieve[i] = i;
for(ll i=2;(i*i)<=n;i++)
if(sieve[i] == i)
for(ll j=(i * i);j<=n;j+=i)
sieve[j] = i;
ll c = 0;
for(ll i=6;i<=n;i++){
fill(pfact, pfact + 4000, 0);
ll t = i;
while(t > 1){
pfact[sieve[t]] = 1;
t /= sieve[t];
}
if(accumulate(pfact, pfact + 4000, (ll) 0) == 2)
c++;
}
cout << c << "\n";
}
int main()
{
freopen("input.txt", "r", stdin); //Comment
freopen("output.txt", "w", stdout); //this out.
ios::sync_with_stdio(false); //Not
cin.tie(NULL); //this.
cout.tie(0); //or this.
solve();
return 0;
}