-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSieve Of Eras basic.cpp
158 lines (94 loc) · 3.42 KB
/
Sieve Of Eras basic.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include<bits/stdc++.h> // "Hello there"
using namespace std;
// ->uncomment for ordered set
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// // typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // for pair
// typedef tree<int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// ->uncomment for unordered map of pairs.
// #include<functional>
// template <typename T>
// inline void hash_combine(std::size_t &seed, const T &val) {seed ^= std::hash<T>()(val) + 0x9e3779b9 + (seed << 6) + (seed >> 2);}
// template <typename T> inline void hash_val(std::size_t &seed, const T &val) {hash_combine(seed, val);}
// template <typename T, typename... Types>
// inline void hash_val(std::size_t &seed, const T &val, const Types &... args) {hash_combine(seed, val); hash_val(seed, args...);}
// template <typename... Types>
// inline std::size_t hash_val(const Types &... args) { std::size_t seed = 0; hash_val(seed, args...);return seed;}
// struct pair_hash
// {
// template <class T1, class T2>
// std::size_t operator()(const std::pair<T1, T2> &p) const
// {
// return hash_val(p.first, p.second);
// }
// };
#define pb push_back
#define ll long long int
#define SORTA(v) sort(v.begin(),v.end())
#define SORTD(v) sort(v.begin(),v.end(),greater<>())
#define endl '\n'
#define FOR(i,n) for(ll i = 0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define REVERSE(s) reverse(s.begin(),s.end())
#define GCD(a,b) __gcd(a,b)
#define VFIND(v1,val) find(v1.begin() , v1.end() , val )
#define VFILL(v1 , val) std::fill(v1.begin(), v1.end(), val);
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
const int MOD = 1e9 + 7;
long long int INF = LLONG_MAX;
void DPM(map<ll,ll>m1)
{
for(auto it = m1.begin();it!=m1.end();it++)
{
cout<<it->first<<" "<<it->second<<endl;
}
cout<<endl;
}
void DPV(vector<ll>v)
{
FOR(i,v.size())cout<<v[i]<<" ";cout<<endl;
}
void DPS(set<ll>s1)
{
for(auto it =s1.begin();it!=s1.end();it++)cout<<*it<<" ";cout<<endl;
}
ll dx[4] = { 0,0,1,-1 };
ll dy[4] = { 1,-1,0,0 };
string pos = "RLDU";
// check the limits dummy
const ll NN = 3* (1e5) + 100;
int main()
{
FAST;
ll i ,j , TC = 1;
// cin>>TC;
ll n = 1e6;
vector<bool>prime(n+1);
fill( prime.begin() , prime.end() , 1);
for(i = 2; i*i <=n; i++)
{
if( prime[i] )
{
for(j = i*i; j<=n; j += i)
{
prime[j] = false;
}
}
}
ll t; cin>>t;
FOR1(i,t)
{
if( prime[i] )cout<<i<<" ";
}
// n*log( log(n) )
}
// vector<vector<int>> vec( n , vector<int> (m, 0)); 2d vector
// to_string(a)
// s1.substr(1,3) 3 char of s1 starting from 1 s1.sub(pos) starting from pos
// assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
// reverse(v1.begin() + a , v1.begin() + b) reverse starting from a to b-1
// A lambda function is written like [](argument1,argument2,.....){//code}
// to create unordered map for pairs unordered_map<pair<ll, ll>, ll, pair_hash> slopeCount;
// unordered_set<pair<ll, ll>, pair_hash> seen;