Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define FIO \
- ios_base::sync_with_stdio(false); \
- cin.tie(NULL); \
- cout.tie(NULL);
- int main()
- {
- FIO;
- int a, b;
- cin >> a >> b;
- for (int i = a; i <= b; i++) {
- // Skip 0 and 1 as they are
- // neither prime nor composite
- if (i == 1 || i == 0)
- continue;
- // flag variable to tell
- // if i is prime or not
- bool flag = 1;
- for (int j = 2; j <= i / 2; ++j) {
- if (i % j == 0) {
- flag = 0;
- break;
- }
- }
- // flag = 1 means i is prime
- // and flag = 0 means i is not prime
- if (flag == 1)
- cout << i << " ";
- }
- }
Add Comment
Please, Sign In to add comment