#include <iostream>
#include <cmath>
using namespace std;
bool eratosthenesSieve(int currentNumber) {
/*
Describe the function that checks if the number is prime and returns a boolean value.
This function is based on the "sieve of Eratosthenes" algorithm.
True - if the number is prime, false - normal.
*/
// If the number equals to 1 or if it even, return false. And if it equals to 2, return true.
if (currentNumber == 2 or currentNumber == 3) {
return true;
} else if (!(currentNumber % 2) or !(currentNumber % 3) or currentNumber == 1) {
return false;
}
// If the number has the divider from 5 to the root of this number with the second step return false.
for (int divider = 5; divider <= sqrt(currentNumber); divider += 2) {
if (!(currentNumber % divider)) {
return false;
}
}
// In all other situations, return true.
return true;
}
void printSequenceOfPrimeNumbers(int beginning, int ending) {
/*
This function prints all prime numbers in a line.
It contains a loop that starts and ends with the given values.
*/
for (int sequenceElement = beginning; sequenceElement <= ending; sequenceElement += 1) {
if (eratosthenesSieve(sequenceElement)) {
cout << sequenceElement << " ";
}
}
}
int main() {
/*
Receive the beginning and end of the sequence.
*/
int beginning, ending;
cin >> beginning >> ending;
// Calling the function.
printSequenceOfPrimeNumbers(beginning, ending);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y21hdGg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCmJvb2wgZXJhdG9zdGhlbmVzU2lldmUoaW50IGN1cnJlbnROdW1iZXIpIHsKCS8qCglEZXNjcmliZSB0aGUgZnVuY3Rpb24gdGhhdCBjaGVja3MgaWYgdGhlIG51bWJlciBpcyBwcmltZSBhbmQgcmV0dXJucyBhIGJvb2xlYW4gdmFsdWUuCglUaGlzIGZ1bmN0aW9uIGlzIGJhc2VkIG9uIHRoZSAic2lldmUgb2YgRXJhdG9zdGhlbmVzIiBhbGdvcml0aG0uCglUcnVlIC0gaWYgdGhlIG51bWJlciBpcyBwcmltZSwgZmFsc2UgLSBub3JtYWwuCgkqLwoJCgkvLyBJZiB0aGUgbnVtYmVyIGVxdWFscyB0byAxIG9yIGlmIGl0IGV2ZW4sIHJldHVybiBmYWx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