-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path406- prime cuts.cpp
executable file
·69 lines (59 loc) · 1.21 KB
/
406- prime cuts.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
#include <iostream>
#include <bitset>
#include <vector>
#include <cmath>
using namespace std;
bitset<10000005> b;
long long SSize;
vector<int> prime;
int N , C;
void sieve(long long upper)
{
SSize = upper;
b.set();
b[0]=b[1]= 0;
for (long long i = 2 ; i <= SSize ;i++ )
{
if(b[i])
{
for ( long long j = i * i ; j <= SSize ; j+= i)
b[j] = 0;
prime.push_back((int)i);
}
}
}
int main ()
{
prime.clear();
while ( cin>>N>>C)
{
prime.clear();
prime.push_back(1);
sieve(N);
int bgn;
int nC;
if ( prime.size() % 2 == 0)
{
bgn = (prime.size()/2) - C;
nC = C*2;
}
else
{
bgn = (prime.size()/2) - C +1;
nC = (C*2) - 1;
}
if ( nC > prime.size())
{
nC = prime.size();
bgn = 0;
}
cout << N << " "<< C<<":";
for ( int i = bgn ; i < nC + bgn ; i++)
{
cout << " " << prime[i];
}
cout << endl;
cout << endl;
}
return 0;
}