-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA_Almost_Prime.cpp
More file actions
69 lines (68 loc) · 1.22 KB
/
A_Almost_Prime.cpp
File metadata and controls
69 lines (68 loc) · 1.22 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long int ll;
//const int N = 2e3 + 100;
const int mod = 1e9 + 7;
vector<ll> fun(ll N)
{
vector<ll> V;
for(ll i=2;i*i<=N;++i)
{
if(N%i==0)
{
if(i*i==N)V.push_back(i);
else V.push_back(N/i),V.push_back(i);
}
}
sort(V.begin(),V.end());
return V;
}
void solve()
{
ll N;cin>>N;
set<ll> V;V.insert(2);
for(ll i=3;i<=N;i+=2)
{
bool ok=false;
for(ll j=2;j*j<=i;++j)
{
if(i%j==0)
{
ok=true;break;
}
}
if(!ok)
{
V.insert(i);
}
}
//sort(V.begin(),V.end());
// for(auto i : V)cout<<i<<' ';cout<<'\n';
ll ans=0;
for(ll i=2;i<=N;++i)
{
vector<ll> A = fun(i);
//for(auto j : A)cout<<j<<' ';cout<<'\n';
ll c=0;
for(ll j=0;j<A.size();++j)
{
if(V.find(A[j])!=V.end())++c;
}
if(c==2)++ans;//,cout<<i<<' ';
}
cout<<ans<<'\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t=1;//cin>>t;
while(t--)
{
solve();
}
return 0;
}