import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class TriangleMaxSum { public static void main(String[] args) { int[][] pyramid = ew int[n][]; int maxSum = findMaxSum(pyramid); System.out.println("Maximum sum of non-prime numbers: " + maxSum); } private static boolean isPrime(int num) { if (num < 2) return false; for (int i = 2; i * i <= num; i++) { if (num % i == 0) return false; } return true; } private static int findMaxSum(int[][] pyramid) { int n = pyramid.length; int[][] dp = new int[n][n]; // Initialize the bottom row of dp with the values from the pyramid for (int i = 0; i < n; i++) { dp[n - 1][i] = isPrime(pyramid[n - 1][i]) ? 0 : pyramid[n - 1][i]; } // Build the dp table from bottom to top for (int i = n - 2; i >= 0; i--) { for (int j = 0; j <= i; j++) { dp[i][j] = isPrime(pyramid[i][j]) ? 0 : pyramid[i][j] + Math.max(dp[i + 1][j], dp[i + 1][j + 1]); } } return dp[0][0]; } }