Hey niaren.

Hint: Try treating n as a continuous variable and using calculus to get the maximum points and look at answers that are integer values around those points.

With regards to the constraints on R and theta, consider using multi-variable optimization with those constraints.

If you get a small number of turning points, then it will be easy to find the values of N that maximizes the function.