class Program { static int[][] list = { new int[] { 1 }, new int[] { 8, 4 }, new int[] { 2, 6, 9 }, new int[] { 8, 5, 9, 3 } }; static bool IsPrime(int num) { if (num < 2) return false; for (int i = 2; i * i <= num; i++) { if (num % i == 0) return false; } return true; } static void Main(string[] args) { int rowCount = list.Length; for (int i = rowCount - 2; i >= 0; i--) { for (int j = 0; j <= i; j++) { if (!IsPrime(list[i][j])) { list[i][j] += Math.Max(list[i + 1][j], list[i + 1][j + 1]); } } } int totalMax = list[0][0]; Console.WriteLine("Sum: " + totalMax); } }