We'll prove that the number of color needed for input n
is ceiling((n-1)^2/2)
,
ie. this OEIS sequence with offset 1.
First we prove that this number is needed.
To satisfy the condition, a square color should be different from all other
squares in a specific range related to n
. This range is the union of all
retangles containing the initial square, and is a diamond shape centered at
this square. For example, n=5
corresponding to this diamond shape: