In Sec. 2 of Landau & Lifshitz's Mechanics, they claim that
Thus the Lagrangian is defined only to within an additive total time derivative of any function of coordinates and time.
by proving that $L$ and $$L'=L+\frac{d}{dt}(f(q,t))$$ are equivalent as far as the least action principle is concerned.
However, is this condition necessary as well as sufficient? That is, can we deduce that $$L'=L+\frac{d}{dt}(f(q,t))$$ for some $f$ from their equivalence when taking the first variation of the action?
This is important because in Sec. 4, Landau tries to find the form of $L$ by requiring $$L'=L+\frac{d}{dt}(f(q,t)).$$ If the condition is not necessary, this shouldn't work.