Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- #include <string>
- #include <vector>
- #include <list>
- using namespace std;
- int main () {
- vector<long> numlist(1,2);
- vector<long> foundlist;
- list<string> cmplist;
- string input;
- long begin, end;
- int imax;
- bool prime;
- numlist.push_back(3);
- getline(cin, input);
- istringstream iss(input, istringstream::in);
- iss >> imax;
- if (imax > 10) imax = 10;
- for (int i = 0; i < imax; i++) {
- getline(cin, input);
- cmplist.push_back(input);
- }
- while (!cmplist.empty())
- {
- begin = 0, end = 0;
- istringstream iss(cmplist.front(), istringstream::in);
- iss >> begin;
- iss >> end;
- if (begin >= 1 && begin < end && end <= 1000000000L && (end-begin <= 100000))
- {
- // find primes here
- if (numlist.back() < end)
- for(long i = numlist.back(); i < end+1; i+=2)
- {
- prime = true;
- for (int j = 0; j < numlist.size(); j++)
- if (!(i % numlist.at(j)))
- {
- prime = false;
- break;
- }
- if (prime)
- numlist.push_back(i);
- }
- // display already found primes here
- for (int i = 0; i < numlist.size() ; i++)
- {
- if (numlist.at(i) >= begin && numlist.at(i) <= end)
- cout << numlist.at(i) << endl;
- else if (numlist.at(i) > end)
- break;
- }
- cout << endl;
- }
- else
- cout << endl;
- cmplist.pop_front();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement