Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <string>
- #include <vector>
- using namespace std;
- const int MAX = 34000;
- int polje[MAX + 1];
- vector <int> prosti;
- void eratosten () {
- for (int i = 2; i <= (int) sqrt (MAX); i++) {
- if (polje[i] == 0) {
- prosti.push_back (i);
- for (int j = i * 2; j <= MAX; j += i) {
- polje[j] = 1;
- }
- }
- }
- }
- int prost (int broj) {
- if (broj == 1) {
- return 0;
- }
- int gg = (int) sqrt (broj);
- for (int i = 0; prosti[i] <= gg; i++) {
- if (broj % prosti[i] == 0) {
- return 0;
- }
- }
- return 1;
- }
- int main() {
- eratosten ();
- int t;
- scanf ("%d", &t);
- for (int i = 0; i < t; i++) {
- int a, b;
- scanf ("%d %d", &a, &b);
- for (int j = a; j <= b; j++) {
- if (prost (j)) {
- printf ("%d\n", j);
- }
- }
- printf ("\n");
- }
- //system ("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment