Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- void SieveOfEratosthenes(int n, int m)
- {
- int size = (m + 1) / 8 + 1;
- unsigned char mark[size];
- memset(mark, 255, sizeof(mark));
- for (int p = 2; p * p <= m; p++)
- {
- if ((1 << (8 - p % 8)) & mark[p / 8])
- {
- for (int i = p * p; i <= m; i += p)
- mark[i / 8] = ((~(1 << (8 - i % 8))) & mark[i / 8]);
- }
- }
- for (int p = n; p <= m; p++)
- if ((1 << (8 - p % 8)) & mark[p / 8])
- std::cout << p << '\n';
- }
- int main()
- {
- int t;
- std::cin >> t;
- while (t--)
- {
- int n, m;
- std::cin >> n >> m;
- SieveOfEratosthenes(n==1 ? ++n : n, m);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement