askarulytarlan

Untitled

Jan 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int a, b;
  6. bool was[1000500];
  7.  
  8. int main() {
  9.  
  10. was[0] = was[1] = true;
  11. cin >> a >> b;
  12. for (int i = 2; i <= 1000000; i++) {
  13. if (was[i] != true) {
  14. if (i * 1ll * i <= 1000000) {
  15. for (int j = i * i; j <= b; j += i)
  16. was[j] = true;
  17. }
  18. }
  19.  
  20. }
  21. int cnt = 0;
  22. for(int i = a; i <= b; i++){
  23. if(was[i] == 0){
  24. cout << i << endl;
  25. cnt++;
  26. }
  27. }
  28. if(cnt == 0){
  29. cout << "Absent";
  30. }
  31.  
  32. return 0;
  33.  
  34. }
Add Comment
Please, Sign In to add comment