View Code of Problem 27

import java.util.Scanner;

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) {
              System.out.println(a);
              return false;
          }
      }
      return true;
    }
}

Double click to view unformatted code.


Back to problem 27