I recently encountered the following beautiful integral and sum :
$$\int_{0}^{\infty} \frac{\sin x}{x} dx = \int_{0}^{\infty} \frac{\sin^{2} x}{x^{2}} dx = \frac{\pi}{2}$$
and
$$\sum_{n=1}^{\infty} \frac{\sin n}{n} = \sum_{n=1}^{\infty} \frac{\sin^{2} n}{n^{2}} = \frac{\pi-1}{2}.$$
You can find the solutions to each integral or sum here and here.
Inspired by the first integral, I wanted to find functions $f$ such that
$$\int_{a}^{b} f(x) dx = \int_{a}^{b} \left[ f(x) \right]^{2} dx$$
for real numbers (or $\pm \infty$) $a$ and $b$. I asked this question on AoPS and here's how one of the replies solved it :
For any continuous function $g$, let constant $k$ be
$$k := \frac{\int_{a}^{b} g(x) dx}{\int_{a}^{b} \left[ g(x) \right]^{2} dx}$$
and define $f$ as $f := kg$ then we get
$$\int_{a}^{b} f(x) dx = \frac{\left[ \int_{a}^{b} g(x) dx \right]^{2}}{\int_{a}^{b} \left[ g(x) \right]^{2} dx} = \int_{a}^{b} \left[ f(x) \right]^{2} dx.$$
Using this solution, we can similarly find functions $f$ such that
$$\int_{a}^{b} f(x) dx = \int_{a}^{b} \left[ f(x) \right]^{n} dx$$
for any natural number $n$. However, for the function $\frac{\sin x}{x}$, I have no idea whether it can be derived from this general solution. In other words, would this general solution give all possible functions $f$? For any natural number $n$ or maybe $n = 2$ for now.
My second question is about the sum. How could one find function $f$ that satisfies
$$\int_{a}^{b} f(x) dx = \int_{a}^{b} \left[ f(x) \right]^{2} dx$$
'And'
$$\sum_{n=1}^{\infty} f(n) = \sum_{n=1}^{\infty} \left[ f(n) \right]^{2}?$$
This can be generalized to $\int_{a}^{b} f(x) dx = \int_{a}^{b} \left[ f(x) \right]^{m} dx$ and $\sum_{n=1}^{\infty} f(n) = \sum_{n=1}^{\infty} \left[ f(n) \right]^{m}$ for natural number $m$, but it's too much at this point.