fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cmath>
  4. #include <cstdio>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. int r;
  11. cout << "Input r: ";
  12. scanf("%d", &r);
  13.  
  14.  
  15. vector <int> v(2*r);
  16.  
  17. int x;
  18. int y;
  19. int z;
  20.  
  21. int i=0;
  22. while(r>0 && i<v.size())
  23. {
  24. cout << "Input n and m: ";
  25. cin >> x;
  26. y=x;
  27. cin >> x;
  28. z=x;
  29. v[i]=y;
  30. v[i+1]=z;
  31. i=i+2;
  32. }
  33.  
  34. int l=0;
  35. while(v[l]!=1 && r>0 && l<v.size() && v[l]>=1 && v[l]<=v[l+1] && v[l+1]<=1000000000 && v[l+1]-v[l]<=100000)
  36. {
  37.  
  38. vector <int> v1;
  39. int n=v[l];
  40. int m=v[l+1];
  41.  
  42. if(n==1)
  43. {
  44. if(m!=1)
  45. {
  46. n=2;
  47. i=n;
  48. while(i <= m)
  49. {
  50. v1.push_back(i);
  51. i=i+1;
  52. }
  53. }
  54. else
  55. {
  56. v1.push_back(1);
  57. }
  58.  
  59. }
  60. else
  61. {
  62. i=n;
  63. while(i <= m)
  64. {
  65. v1.push_back(i);
  66. i=i+1;
  67. }
  68. }
  69.  
  70. i=0;
  71. while(i<v1.size())
  72. {
  73. int j=2;
  74. while( j <= sqrt(v1[i]) )
  75. {
  76. if( ((v1[i])%j==0 && v1[i]!=j))
  77. {
  78. v1.erase (v1.begin()+i);
  79. i=i-1;
  80. break;
  81. }
  82. j=j+1;
  83. }
  84. i=i+1;
  85. }
  86. cout <<endl;
  87. i=0;
  88.  
  89. while(i<=v1.size()-1)
  90. {
  91. printf("%d \n", v1[i]);
  92. i=i+1;
  93. }
  94. l=l+2;
  95. }
  96. }
Success #stdin #stdout 0s 4136KB
stdin
2
1 10
3 5
stdout
Input r: Input n and m: Input n and m: