You should try to cite primary sources whenever possible; in this case, that means citing the original paper "B".
However, as GEdgar says, a textbook may be an easier source for people to find, particularly if that book is the de facto standard text in your field. It is therefore a good idea (and perfectly acceptable) to cite both "A" and "B", for example:
We use the formula given as g = 4x^2 ("B", 1950, "A", 2001).
Personally, I prefer to be more verbose and might write something along the lines of
The formula we use is given by Author B ("B", 1950) as
g = 4x^2.
This was later used [confirmed/ expanded on/ usefully re-derived/ etc] by Author A in their book "A" ("A", 2001).