In Landau & Lifshitz's derivation of the Lagrangian of a free particle in a galilean frame of reference one finds the following argument: the equations of motion in two galilean frames must be identical; hence the respective Lagrangians must differ by the total derivative of a function of the generalized position, and time. This is essentially the converse of what the authors point to as justification, namely that adding such a term to the Lagrangian leaves the equations unchanged, and I don't really get why it holds. The only relevant answer I found on stackexchange is Qmechanics' take in Deriving the Lagrangian for a free particle, but i must admit it doesn't quite satisfy me.
Edit: I'm asking why modifications of the Lagrangian that don't change the EL equations are necessarily the addition of a total derivative (and multiplication by a scalar), like L&L claims.