import java.util.Scanner; public class Main { public static boolean isTrue(int num) { if(num == 1) { return false; } else { for(int j = 2;j <= Math.sqrt(num);j++) { if(num % j == 0) { return false; } } return true; } } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while(scanner.hasNext()) { int a = scanner.nextInt(); int b = scanner.nextInt(); if(a > b) { int temp = a; a = b; b = temp; } int sum = 0; for(int i = a + 1;i < b;i++) { if(isTrue(i)) { sum += i; } } System.out.println(sum); } } } |
Double click to view unformatted code.