package assignment; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class main { public static void main(String args[]) throws FileNotFoundException { File f = new File("input.txt"); Scanner scanner = new Scanner(f); int result = 0; result += scanner.nextInt(); scanner.nextLine(); int counter = 0; while(scanner.hasNextLine()) { String line = scanner.nextLine(); String[] arr = line.split(" "); int max = 0; int idx = counter; // System.out.println(i); int value1 = Integer.parseInt(arr[idx]); int value2 = Integer.parseInt(arr[idx+1]); if(isPrime(value1)) { max = value2; counter = idx+1; } else if(isPrime(value2)) { max = value1; counter = idx; } else { max = Math.max(value1, value2); if(max==value1) { counter = idx; } else { counter = idx+1; } } result+=max; } System.out.println("result: "+result); } static boolean isPrime(int val) { if(val<2) { return false; } for (int i = 2; i < val; i++) { if (val % i == 0) { return false; } } return true; } }