fork download
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class Main {
  5. public static void main (String[]args)throws Exception{
  6.  
  7.  
  8. long []Primes=new long[10000000];
  9. Primes[0] = 2;
  10. int i = 0,q=0,sum=0,t = Integer.parseInt(read.readLine());
  11. boolean flag = true;
  12. long start, end,c=2,tester,n,m,holder;
  13. double root,root2;
  14. long counter = 1;
  15. String[] string;
  16.  
  17. while (counter<=t){
  18. string = read.readLine().split(" ");
  19. n = Long.parseLong(string[0]);
  20. m = Long.parseLong(string[1]);
  21. start = System.currentTimeMillis();
  22.  
  23.  
  24. holder = n;
  25. q = 0;
  26. i = 0;
  27. Primes[0] = 2;
  28. c = 2;
  29. flag = true;
  30.  
  31. n = (int)Math.sqrt(1000000000);
  32. if (holder == 1){
  33. c++;
  34. n = 2;
  35. holder = 2;
  36. }
  37.  
  38.  
  39.  
  40.  
  41. while (c <= n){
  42. root = (int)Math.sqrt(c);
  43. while ( q <= i && Primes[q] <= root){
  44. tester = c % Primes[q];
  45. if (tester == 0){
  46. flag = false;
  47. break;
  48. }
  49. q++;
  50. }
  51. if ( flag == true){
  52. Primes[i+1] = c;
  53. i++;
  54. }
  55. c++;
  56. q = 0;
  57. flag = true;
  58. }
  59.  
  60. c = holder;
  61. q = 0;
  62. flag = true;
  63. root = 0;
  64.  
  65.  
  66.  
  67. while ( c < m){
  68. root = Math.sqrt(c);
  69. q = 0;
  70. while (n <= root){
  71. while ( q <= i){
  72. tester = n % Primes[q];
  73. if (tester == 0){
  74. flag = false;
  75. break;
  76. }
  77. q++;
  78. }
  79.  
  80. if ( flag == true){
  81. Primes[i+1] = n;
  82. i++;
  83. }
  84. q = 0;
  85. flag = true;
  86. n++;
  87. }
  88. n = holder;
  89. q = 0;
  90. while ( q <= i && Primes[q] <= root){
  91. if ( c == 2){
  92. System.out.println(c);
  93. sum++;
  94. flag = false;
  95. }/*else if(c%2==0 || c%3==0||c%5==0){
  96.   flag=false;
  97.   break;
  98.   }
  99.  
  100.   *
  101.   */
  102. else if ( c % Primes[q] == 0){
  103. flag = false;
  104. break;
  105. }
  106. q++;
  107. }
  108. if (flag == true){
  109. System.out.println(c);
  110. sum++;
  111. }
  112. c++;
  113. flag = true;
  114. q = 0;
  115. }
  116. end = System.currentTimeMillis();
  117. System.out.println("\nExecution time: " + (end-start) + " milliseconds.\n" + sum);
  118. counter++;
  119.  
  120.  
  121.  
  122.  
  123.  
  124. }
  125. }
  126. }
  127.  
Runtime error #stdin #stdout 0.11s 212416KB
stdin
2
999900000 1000000000
1 100000
stdout
Standard output is empty