Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <array>
- #include <vector>
- #include <math.h>
- const int _max = 1000000000;
- using namespace std;
- bool IsPrime(const int& n, std::vector<int>& v) {
- double root = sqrt(n);
- auto it = v.begin();
- while (it != v.end() && *it <= root) {
- if(! (n % *it)) return false;
- it++;
- }
- return true;
- }
- void Primes(int min, int finish) {
- static std::vector<int> prime_array;
- static bool z = true;
- if (z) {
- z = false;
- for (int i = 2; i <= sqrt(_max); ++i) {
- if(IsPrime(i, prime_array)) {
- prime_array.push_back(i);
- }
- }
- }
- for (int i = min; i <= finish; ++i) {
- if (IsPrime(i, prime_array)) {
- std::cout << i << std::endl;
- }
- }
- }
- int main() {
- int t = 0;
- std::cin >> t;
- for(int i = 0; i < t; ++i) {
- int m,n = 0;
- std::cin >> m;
- std::cin >> n;
- Primes(m,n);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement