Tie-up will bring to an end the drugstore chain’s century-long run as a public company