Difficult Calculus(?) problem For the function $f(x)$, find the constant n where $f(x)$ has a maximum at $(n,1)$$$f(x)=\frac{x^{n-x}}{(n-x)!}$$
It is roughly $0.561459...$, but this is through numerical guess and check work. I'm fairly confident that the solution will be some infinite series that involves the Euler-Mascheroni constant and the digamma function, along with the Reimann-Zeta function, but I haven't been able to work anything out that leads to any kind of evidence to suggest it even has a way to express $n$ as anything more than a numerical value. 
Some of you may be wondering how I know that it can even have a maximum at $(n,1)$. you'll notice that when $n=x$, $f(x)=1$ and I'm not sure how to describe this so just play with the value of $n$ on https://www.desmos.com/calculator/jb8x3n0cya and you'll see how the graph works. The values that intercept with $y=1$ are what I've found to be important.
P.S. Should $f(x)$ be $f(x,n)$? I'm really not sure.
 A: Using the derivative of $x^x$,
$$(x^x)' = (\ln x + 1) x^x$$
Using the derivative of $n!$,
$$(n!)' = n!\left(-\gamma + \sum_{k = 1}^{n} \frac{1}{k}\right)$$
Note that we really have to replace factorial with the Gamma function to make sense of differentiation. But lucky, we only need to know the value of its derivative at nonnegative integer so the above formula suffices. (Be careful, the above formula works only when $n$ is a nonnegative integer.)
Now regards $f$ as a function of $x$ on $(-\infty, n + 1)$. Here we again replace factorial with Gamma function so that $f$ is well-defined on $(-\infty, n + 1)$.
$$f'(x) = \left(\frac{x^{n - x}}{(n - x)!}\right)'$$
$$= \left(\frac{x^n}{x^x (n - x)!}\right)'$$
$$= \frac{x^x (n - x)! (x^n)' - x^n (x^x (n - x)!)'}{(x^x (n - x)!)^2}$$
$$= \frac{x^x(n - x)!n x^{n - 1} - x^n((x^x)'(n - x)! + x^x ((n - x)!)')}{(x^x (n - x)!)^2}$$
$$= \frac{x^x(n - x)!n x^{n - 1} - x^n\left((\ln x + 1) x^x(n - x)! + x^x \left(-(n - x)!\left(-\gamma + \sum_{k = 1}^{n - x} \frac{1}{k}\right)\right)\right)}{(x^x (n - x)!)^2}$$
(Be careful, the above formula works only when $n - x$ is a nonnegative integer.)
Putting $x = n$ and $f' = 0$ (we can do it since $n - x = n - n = 0$ is a nonnegative integer),
$$f'(n) = \frac{n^n(n - n)!n n^{n - 1} - n^n\left((\ln n + 1) n^n(n - n)! + n^n \left(-(n - n)!\left(-\gamma + \sum_{k = 1}^{n - n} \frac{1}{k}\right)\right)\right)}{(n^n (n - n)!)^2}$$
$$= \frac{n^n n^n - n^n((\ln n + 1) n^n + n^n \gamma)}{(n^n)^2}$$
$$= 1 - (\ln n + 1 + \gamma)$$
$$= -\ln n - \gamma$$
$$= 0$$
So $n = e^{-\gamma}$ is the unique critical point. Since $f$ is differentiable on $(-\infty, n + 1)$ and $(-\infty, n + 1)$ has no end points, the global maximum (which exists according to the question) must be a critical point. Hence $n = e^{-\gamma}$ is the unique global maximum.
