This problem was a mathematics competition. The strategy is to complete thew square and use the properties of integers to find the maximum of of n