View Code of Problem 27

class Main{
  
    public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      while (scanner.hasNextInt()) {
          int a = scanner.nextInt();
          int b = scanner.nextInt();
          if (a > b) {
              int temp = a;
              a = b;
              b = temp;
          }
          int res = 0;
          for (int i = a + 1; i < b; i++) {
              if (judge(i)) {
                  res += i;
              }
          }
          System.out.println(res);
      }
    }
    
    public static boolean judge(int a){

      for (int i = 2; i <= (int)Math.sqrt(a); i++) {
          if (a % i == 0) {
              return false;
          }
      }
      return true;
    }
}
/*
Main.java:4: error: cannot find symbol
      Scanner scanner = new Scanner(System.in);
      ^
  symbol:   class Scanner
  location: class Main
Main.java:4: error: cannot find symbol
      Scanner scanner = new Scanner(System.in);
                            ^
  symbol:   class Scanner
  location: class Main
2 errors
*/

Double click to view unformatted code.


Back to problem 27