S&P, Nasdaq gain over 1% each as US stocks close higher