File tree Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Expand file tree Collapse file tree 2 files changed +15
-8
lines changed Original file line number Diff line number Diff line change 2
2
3
3
using namespace std ;
4
4
5
- const int maxn = 10101010 ;
5
+ const int maxn = 101010101 ;
6
6
7
7
int lp[maxn];
8
8
@@ -33,4 +33,5 @@ int main()
33
33
for (int p : ans)
34
34
cout << p << " " ;
35
35
cout << " \n " ;
36
+ // cout << ans.size() << "\n";
36
37
}
Original file line number Diff line number Diff line change @@ -6,21 +6,27 @@ const int maxn = 101010101;
6
6
7
7
char s[maxn];
8
8
// bitset<maxn> s;
9
- vector<int > primes;
10
9
11
-
12
- void init ()
10
+ vector<int > sieve (int n)
13
11
{
14
- for (int i = 2 ; i*i < maxn ; i++)
12
+ for (int i = 2 ; i*i <= n ; i++)
15
13
if (!s[i])
16
- for (int j = i*i; j < maxn ; j += i)
14
+ for (int j = i*i; j <= n ; j += i)
17
15
s[j] = 1 ;
18
16
19
- for (int i = 2 ; i < maxn; i++)
17
+ vector<int > primes;
18
+ for (int i = 2 ; i <= n; i++)
20
19
if (!s[i]) primes.push_back (i);
20
+
21
+ return primes;
21
22
}
22
23
23
24
int main ()
24
25
{
25
- init ();
26
+ int n;
27
+ cin >> n;
28
+
29
+ auto ans = sieve (n);
30
+
31
+ cout << ans.size () << " \n " ;
26
32
}
You can’t perform that action at this time.
0 commit comments