fork(11) download
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <map>
  5. #define lli long long int
  6. #define inf 10000000001
  7. using namespace std;
  8. int count[1000001];
  9. int store[88888];
  10. int main() {
  11. int p = 2,d = 0;
  12. lli n = sqrt(inf);
  13. while (p <= n) {
  14. store[d++] = p;
  15. for (lli j = 2; j <= n/p; j++) {
  16. count[p*j] = 1;
  17. }
  18. int l;
  19. for (l = p + 1; l <= n; l++) {
  20. if (count[l] == 0) {
  21. p = l;
  22. break;
  23. }
  24. }
  25. if (l == n + 1) {
  26. break;
  27. }
  28. }
  29. int t;
  30. scanf("%d",&t);
  31. while (t--) {
  32. int l,r,x = 0,ct = 0;
  33. scanf("%d %d",&l,&r);
  34. map <int,int> m1;
  35. p = store[x];
  36. while (x < d && p <= sqrt(r)) {
  37. int z = l/p;
  38. if (l % p == 0) {
  39. m1[l] = 1;
  40. }
  41. if (l <= p) {
  42. z = 1;
  43. }
  44. for (int i = z+1; i <= r/p; i++) {
  45. m1[p*i] = 1;
  46. }
  47. p = store[++x];
  48. }
  49. for (int i = l; i <= r; i++) {
  50. if (i == 1) {
  51. continue;
  52. }
  53. if (m1[i] == 0) {
  54. printf("%d\n",i);
  55. }
  56. }
  57. printf("\n");
  58. }
  59. return 0;
  60. }
Runtime error #stdin #stdout 0.03s 7400KB
stdin
Standard input is empty
stdout