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){ if (a == 1) { return false; } for (int i = 2; i <= (int)Math.sqrt(a); i++) { if (a % i == 0) { return false; } } return true; } } |
Double click to view unformatted code.