萧十郎
输入有多组数据,你的代码只处理了一组数据就退出了。加一个while (scanner.hasNext())的判断就好了。import java.util.Scanner;/** * Created by kbyyd on 2016/3/21. */public class Main { // main -> Main public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()) { // add while loop int n = scanner.nextInt(); XiaoYi xiaoyi = new XiaoYi(scanner.nextInt()); for (int i = 0; i < n; i++) { xiaoyi.addAbility(scanner.nextInt()); } System.out.println(xiaoyi.getAbility()); } scanner.close(); }}class XiaoYi { private int ability; XiaoYi(int ability) { this.ability = ability; } public void addAbility(int b) { if (ability >= b) ability += b; else ability += getDivisor(b); } public int getAbility() { return this.ability; } private int getDivisor(int b) { if (b < ability) return 0; int a = ability; int s = -1; do { s = b % a; b = a; a = s; } while (s != 0); return b; }}