fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5.  
  6.  
  7. int main() {
  8. int n, m;
  9. cin >> n >> m;
  10.  
  11. vector <bool> v(m + 1, true);
  12.  
  13.  
  14. for (int i = 2; i * i <= m; i++) {
  15. if (v[i]) {
  16. for (int j = i * i; j <= m; j += i) {
  17. v[j] = false;
  18. }
  19. }
  20. }
  21.  
  22. string res = "";
  23.  
  24. for (int i = n; i <= m; i++) {
  25. if (v[i]) {
  26. res += to_string(i);
  27. res += "\n";
  28. }
  29. }
  30.  
  31. if (res.length() > 0) {
  32. cout << res;
  33. } else {
  34. cout << "Absent";
  35. }
  36.  
  37.  
  38. }
Success #stdin #stdout 0s 5320KB
stdin
4 4
stdout
Absent