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 sc = new Scanner(f); int n = 0; while (sc.hasNextLine()) { sc.nextLine(); n++; } int[][] arr = new int[n][n]; Scanner scanner = new Scanner(f); for(int i = 0 ; i 0; idx--) { for (int i = 0; i < arr[idx].length - 1; i++) { if (!isPrime(arr[idx - 1][i]) || (idx == 1)) { if (idx == arr.length - 1) { arr[idx - 1][i] += Math.max(isPrime(arr[idx][i]) ? 0 : arr[idx][i], isPrime(arr[idx][i + 1]) ? 0 : arr[idx][i + 1]); } else { arr[idx - 1][i] += Math.max(arr[idx][i], arr[idx][i + 1]); } } else { arr[idx - 1][i] = 0; } } } System.out.println("result: "+arr[0][0]); } 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; } }