Equation (31-1) of UBC 1997 is easier to apply but gives conservative results as it considers that the non-structural element will be subjected to four times the peak ground acceleration irrespective of its locations in the building.
In that formula Ca = horizontal seismic coefficient (basically the peak ground acceleration) for a particular soil profile type and zone factor. The "response" of non-structural element isn't considered by (31-1).

On the other hand, Equation (31-2) which can be alternatively considered, it's more accurate as it considers different parameters on which the response of non-structural elements is dependent (that's why Ca is replaced by Ca*ap/Rp).
It assumes (conservatively enough) that a non-structural element attached to the roof of a building will experience four times the acceleration that a similar element attached to the ground floor of the same building experiences (i.e 4*Ca*ap/Rp vs. Ca*ap/Rp).
That's why it considers a trapezoidal distribution of floor accelerations, linearly increasing from the acceleration at the ground to the acceleration at the roof- this is the factor 1+3*hx/hr.

I would recommend you (31-2) if you have the freedom to consider it. In my opinion (31-1)is very conservative.

Please note that what I've written is related to piping as "non-structural" i.e is attached to or housed in a "building" or "building system", (of course) being not part of the main load-resisting structural system of the building....

Best regards,