Search for high-mass Z gamma resonances in proton-proton collisions at sqrt(s) = 8 and 13 TeV using jet substructure techniques