An explicit formula for optimal carbon taxes under general economic settings