Solution to a functional equation and its application to stable and stable-type distributions