fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Main {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. int a, b;
  9. int number1, number2;
  10. int counter = 0;
  11. Scanner sc = new Scanner(System.in);
  12. a = sc.nextInt();
  13. b = sc.nextInt();
  14. if(a > b) {
  15. a += b;
  16. b = a - b;
  17. a -= b;
  18. }
  19. if (a == 1) counter--;
  20. for (int i = a; i <= b; i++){
  21. number1 = i;
  22. boolean f1 = true;
  23. boolean f2 = true;
  24. for (int j = 2; j*j <= number1; j++){
  25. f1 = ((number1%j)!=0);
  26. if (!f1)
  27. break;
  28. }
  29. if (f1){
  30. number2 = 0;
  31. while (number1 > 0) {
  32. number2 = number2*10 + number1%10;
  33. number1 /= 10;
  34. }
  35. for (int j = 2; j*j <= number2; j++){
  36. f2 = ((number2%j)!=0);
  37. if (!f2) break;
  38. }
  39. if (f2) counter++;
  40. }
  41. }
  42. System.out.format("%d", counter);
  43. }
  44. }
Success #stdin #stdout 0.15s 321280KB
stdin
9900 10000
stdout
4