Solution 1: We first prove the left hand side inequality. We begin by drawing an n×n board, with corners at (0,0), (n,0), (0,n) and (n,n) on the Cartesian plane.
Consider the line ℓ with slope r passing through (0,0). For each j∈{1,…,n}, consider the point (j,min(jr,n)). Note that each such point either lies on ℓ or the top edge of the board. In the jth column from the left, draw the rectangle of height min(jr,n). Note that the sum of the n rectangles is equal to the area of the board under the line ℓ plus n triangles (possibly with area 0) each with width at most 1 and whose sum of the heights is at most n. Therefore, the sum of the areas of these n triangles is at most n/2. Therefore, ∑j=1nmin(jr,n) is at most the area of the square under ℓ plus n/2.
Consider the line with slope 1/r. By symmetry about the line y=x, the area of the square under the line with slope 1/r is equal to the area of the square above the line ℓ. Therefore, using the same reasoning as before, ∑j=1nmin(j/r,n) is at most the area of the square above ℓ plus n/2.
Therefore, ∑j=1nfj(r)=∑j=1n(min(jr,n)+min(rj,n)) is at most the area of the board plus n, which is n2+n. This proves the left hand side inequality.
To prove the right hand side inequality, we will use the following lemma:
Lemma: Consider the line ℓ with slope s passing through (0,0). Then the number of squares on the board that contain an interior point below ℓ is ∑j=1nmin(⌈js⌉,n).
Proof of Lemma: For each j∈{1,…,n}, we count the number of squares in the jth column (from the left) that contain an interior point lying below the line ℓ. The line x=j intersect the line ℓ at (j,js). Hence, since each column contains n squares total, the number of such squares is min(⌊js⌋,n). Summing over all j∈{1,2,…,n} proves the lemma. End Proof of Lemma
By the lemma, the rightmost expression of the inequality is equal to the number of squares containing an interior point below the line with slope r plus the number of squares containing an interior point below the line with slope 1/r. By symmetry about the line y=x, the latter number is equal to the number of squares containing an interior point above the line with slope r. Therefore, the rightmost expression of the inequality is equal to the number of squares of the board plus the number of squares of which ℓ passes through the interior. The former is equal to n2. Hence, to prove the inequality, it suffices to show that every line passes through the interior of at least n squares. Since ℓ has positive slope, each ℓ passes through either n rows and/or n columns. In either case, ℓ passes through the interior of at least n squares. Hence, the right inequality holds. □
Solution 2: We first prove the left inequality. Define the function f(r)=∑j=1nfj(r). Note that f(r)=f(1/r) for all r>0. Therefore, we may assume that r≥1.
Let m=⌊n/r⌋, where ⌊x⌋ denotes the largest integer less than or equal to x. Then min(jr,n)=jr for all j∈{1,…,m} and min(jr,n)=n for all j∈{m+1,…,n}. Note that since r≥1, min(j/r,n)≤n for all j∈{1,…,n}. Therefore,
f(r)=j=1∑nfj(r)=(1+2+⋯+m)r+(n−m)n+(1+2+⋯+n)⋅r1=2m(m+1)⋅r+2n(n+1)⋅r1+n(n−m)(1)
Then by (2), note that f(r)≤n2+n if and only if
2m(m+1)r+2rn(n+1)≤n(m+1)
if and only if
m(m+1)r2+n(n+1)≤2rn(m+1)(2)
Since m=⌊n/r⌋, there exist a real number b satisfying 0≤b<r such that n=mr+b. Substituting this into (2) yields
m(m+1)r2+(mr+b)(mr+b+1)≤2r(mr+b)(m+1),
2m2r2+mr2+(2mb+m)r+b2+b≤2m2r2+2mr2+2mbr+2br,
which simplifies to mr+b2+b≤mr2+2br⇔b(b+1−2r)≤mr(r−1)⇔b((b−r)+(1−r))≤mr(r−1). This is true since
b((b−r)+(1−r))≤0≤mr(r−1),
which holds since r≥1 and b<r. Therefore, the left inequality holds.
We now prove the right inequality. Define the function g(r)=∑j=1n=gj(r). Note that g(r)=g(1/r) for all r>0. Therefore, we may assume that r≥1. We will consider two cases; r≥n and 1≤r<n.
If r≥n, then min(⌈jr⌉,n)=n and min(⌈j/r⌉,n)=1 for all j∈{1,…,n}. Hence, gj(r)=n+1 for all j∈{1,…,n}. Therefore, g(r)=n(n+1)=n2+n, implying that the inequality is true.
Now we consider the case 1≤r<n. Let m=⌊n/r⌋. Hence, jr≤n for all j∈{1,…,m}, i.e. min(⌈jr⌉,n)=⌈jr⌉ and jr≥n for all j∈{m+1,…,n}, i.e. min(⌈jr⌉,n)=n. Therefore,
j=1∑nmin(⌈jr⌉,n)=j=1∑m⌈jr⌉+(n−m)n.(3)
We will now consider the second sum ∑j=1nmin{⌈j/r⌉,n}.
Since r≥1, min(⌈j/r⌉,n)≤min(⌈n/r⌉,n)≤n. Therefore, min(⌈j/r⌉,n)=⌈j/r⌉. Since m=⌊n/r⌋, ⌈n/r⌉≤m+1. Since r>1, m<n, which implies that m+1≤n. Therefore, min{⌈j/r⌉,n}=⌈j/r⌉≤⌈n/r⌉≤m+1 for all j∈{1,…,n}.
For each positive integer k∈{1,…,m+1}, we now determine the number of positive integers j∈{1,…,n} such that ⌈j/r⌉=k. We denote this number by sk.
Note that ⌈j/r⌉=k if and only if k−1<j/r≤k if and only if (k−1)r<j≤min(kr,n), since j≤n. We will handle the cases k∈{1,…,m} and k=m+1 separately. If k∈{1,…,m}, then min(kr,n)=kr, since r≤m and m=⌊n/r⌋.
The set of positive integers j satisfying (k−1)r<j≤kr is {⌊(k−1)r⌋+1,⌊(k−1)r⌋+2,…,⌊kr⌋}. Hence,
sk=⌊rk⌋−(⌊r(k−1)⌋+1)+1=⌊rk⌋−⌊r(k−1)⌋
for all k∈{1,…,m}. If k=m+1, then (k−1)r<j≤min(kr,n)=n. The set of positive integers j satisfying (k−1)r<j≤kr is {⌊(k−1)r⌋+1,…,n}. Then sm+1=n−⌊r(k−1)⌋=n−⌊mr⌋. Note that this number is non-negative by the definition of m. Therefore, by the definition of sk, we have
j=1∑nmin(⌊rj⌋,n)=k=1∑m+1ksk=k=1∑m(k(⌊kr⌋−⌊(k−1)r⌋))+(m+1)(n−⌊rm⌋)=(m+1)n−k=1∑m⌊kr⌋.(4)
Summing (??) and (??) yields that
g(r)=n2+n+j=1∑m(⌈jr⌉−⌊jr⌋)≥n2+n,
which proves the right inequality. □