The equation is $$\nabla a=\vec{B},$$ $$a=?$$
Example 1: $\vec{B}=\mbox{const}$. Then $$a=\vec{B}\cdot \vec{x},$$ where $\vec{x}$ is the position vector. This is true since $\nabla(\vec{B}\cdot \vec{x})=\vec{B}$
Could you give other examples? Most interestingly, what happens when $\vec{B}$ is no longer constant? What does $a$ equal then?
Since the curl of a gradient is zero, $\vec{B}$ has to satisfy $\nabla \times \vec{B} = 0$ for this equation to make sense (take the curl of both sides to see this). This condition is actually the key to finding the inverse.
Suppose we have a simply-connected open region $\Omega \subseteq \mathbb{R}^3$ where $\nabla a = \vec{B}$. Define $$ A(\gamma) = \int_{\gamma} \vec{B} \cdot d\vec{x}, $$ where $\gamma:[0,1] \to \Omega$ is a smooth curve joining the fixed point $\vec{x}_0 \in \Omega$ to $\vec{x}$. Now, we can show that $A$ in fact only depends on the endpoint: if $\gamma'$ is another smooth curve joining $\vec{x}_0$ to $\vec{x}$, $$A(\gamma)-A(\gamma') = \int_{\Gamma} \vec{B} \cdot d\vec{x}, $$ where $\Gamma$ is a piecewise-smooth closed curve, which we assume does not intersect itself. Since $\Omega$ is simply-connected, $\Gamma$ bounds a two-dimensional surface, and so Stokes's Theorem implies that the right-hand side is zero because the curl of $\vec{B}$ is zero. Hence $A=A(\vec{x})$.
One can also show that $\nabla A = \vec{B}$: $$ A(\vec{x}+\vec{h})-A(\vec{x})-\vec{h} \cdot \vec{B}(\vec{x}) = \int_{\vec{x}}^{\vec{x}+\vec{h}} (\vec{B}(\vec{x}')-\vec{B}(\vec{x})) \cdot d\vec{x}', $$ and since $\vec{B}$ is continuous (or it wouldn't be differentiable), the integral is $o(\lVert h \rVert)$, so $\nabla A =\vec{B}$.
Therefore $A$ is always a solution to the original equation.
(The same result holds in higher dimensions using the exterior derivative instead of curl, and the more general version of Stokes.)