Consider being given the description of a function $f: \{0, 1\}^n \rightarrow \{0, 1\}^m$ and the binary representation of an integer $k$. Is the state \begin{equation} |\psi_{f, k}\rangle = \frac{1}{\sqrt{2^n}} \sum_{x \in \{0, 1\}^n} |x\rangle |f(x)~\text{mod}~k\rangle \end{equation}
preparable by a polynomial time quantum algorithm?
Note that it is easy to prepare \begin{equation} |\psi_{f}\rangle = \frac{1}{\sqrt{2^n}} \sum_{x \in \{0, 1\}^n} |x\rangle |f(x)\rangle. \end{equation}
But I do not know how to go from there to $|\psi_{f, k}\rangle$.