Optimal Convergence for Distributed Learning with Stochastic Gradient Methods and Spectral-Regularization Algorithms