Facebook
From alperen, 7 Months ago, written in C#.
Embed
Download Paste or View Raw
Hits: 478
  1. class Program
  2. {
  3.     static int[][] list = {
  4.         new int[] { 1 },
  5.         new int[] { 8, 4 },
  6.         new int[] { 2, 6, 9 },
  7.         new int[] { 8, 5, 9, 3 }
  8.     };
  9.  
  10.     static bool IsPrime(int num)
  11.     {
  12.         if (num < 2)
  13.             return false;
  14.         for (int i = 2; i * i <= num; i++)
  15.         {
  16.             if (num % i == 0)
  17.                 return false;
  18.         }
  19.         return true;
  20.     }
  21.  
  22.     static void Main(string[] args)
  23.     {
  24.         int rowCount = list.Length;
  25.  
  26.         for (int i = rowCount - 2; i >= 0; i--)
  27.         {
  28.             for (int j = 0; j <= i; j++)
  29.             {
  30.                 if (!IsPrime(list[i][j]))
  31.                 {
  32.                     list[i][j] += Math.Max(list[i + 1][j], list[i + 1][j + 1]);
  33.                 }
  34.             }
  35.         }
  36.  
  37.         int totalMax = list[0][0];
  38.         Console.WriteLine("Sum: " + totalMax);
  39.     }
  40. }
  41.