-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlmostPrime.cpp
More file actions
71 lines (61 loc) · 1015 Bytes
/
AlmostPrime.cpp
File metadata and controls
71 lines (61 loc) · 1015 Bytes
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
70
71
//CodeForces 26A
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
int main(){
int a;
cin >> a;
vector<int> pri;
vector<int> result;
vector<int> com;
for (int k = 1; k <= a; k++){
if (k == 1){
continue;
}
if (k == 2 || k == 3){
pri.push_back(k);
continue;
}
bool ispri = true;
for (auto it = pri.begin(); it != pri.end(); ++it){
if (k % (*it) == 0){
ispri = false;
break;
}
}
if (ispri == true){
pri.push_back(k);
}
}
int prisz = pri.size();
for (int i = 0; i < prisz -1 ; ++i){
for (int j = i + 1; j < prisz; ++j){
if (pri[i]*pri[j] > a){
break;
}
com.push_back(pri[i]*pri[j]);
}
}
int comsz = com.size();
for (int k = 1; k <= a; ++k){
int dv = 0;
for (int i = 0; i < comsz; ++i){
if (k % com[i] == 0){
dv += 1;
}
if (dv >= 2){
break;
}
}
if (dv == 1){
result.push_back(k);
}
else{
continue;
}
}
cout << result.size() << endl;
return 0;
}