[JAVA] Programming problem "4 Queen Square"

5 7 11 13
101 103 107 109
191 193 197 199
821 823 827 829

The above 4 * 4 square matrix is different from each other, and the sum of all four cells is 1134. Example: 5+103+197+829=1134 101+7+827+199=1134

In this question, a quaternary square matrix for which the calculation "the total values of all four cells with different matrices are the same" is called "4 queen squares".

  1. Create a method isFourQueensSquare (int v1, int v2 ... v16): boolean that takes 16 numbers as arguments and determines if it is a 4-queen square. The method shall return true if it is a 4-queen square and false if it is not a 4-queen square.
  2. Create a method isFourQueensSquare (int v [] []): boolean that takes a 4 * 4 array as an argument and determines if it is a 4-queen square.
  3. Create a method createFourQueensSquare (int min): int [] [] that creates a 4-queen square consisting of 16 different prime numbers. Here, min is a value that specifies the minimum value of the prime numbers that make up the 4-queen square. (min <= minimum prime number)

bonus. 4. Is there an infinite number of 4 queen squares consisting of 16 different prime numbers? Prove it.

Originally, it seems that it was a math quiz for children, but I dared to make it like a programming problem for newcomer training. For my personal interest, I came up with the idea of "prime numbers where all 16 numbers are different". It consisted of four prime numbers. It may be interesting to consider a prime number 4 queen square where the total value of 16 squares is smaller than this.

Recommended Posts

Programming problem "4 Queen Square"
Programming problem collection (Q31-Q35)
[Python] Dynamic programming knapsack problem
Programming problem collection (Q11 to Q15)
[Mathematical optimization problem] Linear programming using PuLP