View Code of Problem 27

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String[] split = scanner.nextLine().split(" ");
            Integer v1 = Integer.valueOf(split[0]);
            Integer v2 = Integer.valueOf(split[1]);
            int sum = 0;
            for (int i = v1 + 1; i < v2; i++) {
                boolean flag = false;
                for (int j = 2; j <= (i / 2) + 1; j++) {
                    if (i % j == 0) {
                        flag = true;
                        break;
                    }
                }
                if (!flag) {
                    sum += i;
                }
            }
            System.out.println(sum);
        }
    }
}

Double click to view unformatted code.


Back to problem 27