Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define max 9000
- #define pb push_back
- #define pairs pair<int, int>
- #define vi vector<int>
- #define vb vector<bool>
- #define vii vector<pairs>
- #define lb lower_bound
- #define ub upper_bound
- #define lli long long int
- #define endl '\n'
- using namespace std;
- bool isPrime[max];
- vi Prime;
- vi output;
- void sieve() {
- memset(isPrime, true, sizeof(isPrime)); // first all odd number's prime
- isPrime[0] = 0;
- // Sieve
- for (int i = 2; i * i <= max; i++) {
- if(isPrime[i]) {
- for (int j = i * i; j <= max; j += i) {
- isPrime[j] = 0;
- }
- }
- }
- }
- int main() {
- #ifndef Niloy
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- sieve();
- for (int i = 0; i <= max; i++) {
- if(isPrime[i] == 1) {
- Prime.push_back(i);
- }
- }
- int n, c, length;
- while(cin >> n >> c) {
- output.clear();
- length = 0;
- cout << n << " " << c << ":";
- for (int i = 0; i < n; i++) {
- if(Prime[i] <= n) {
- output.push_back(Prime[i]);
- length++;
- }
- }
- int mid = middle(length);
- mid += 1;
- cout << mid << " " << length << endl;
- if(length < 2 * c) {
- for (int i = 0; i < output.size(); i++) {
- cout << " " << output[i];
- }
- } else if(length % 2 == 0) {
- int b = c - 1;
- cout << b << endl;
- int low = mid - b;
- int high = mid + c;
- cout << low << " " << high << endl;
- for (int i = low - 2; i < high - 1; i++) {
- cout << " " << output[i];
- }
- } else {
- int b = c - 1;
- int low = mid - b;
- int high = mid + b;
- for (int i = low - 1; i < high; i++)
- cout << " " << output[i];
- }
- cout << endl << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement