The logic behind philanthropy