题解 | #小易的升级之路#
小易的升级之路
http://www.nowcoder.com/practice/fe6c73cb899c4fe1bdd773f8d3b42c3d
难点:接受数据;求最大公约数
public class Main{
public static int gcd(int a,int b){
int c;
while(b!=0){
c=a%b;
a=b;
b=c;
}
return a;
// return b==0?a:gcd(b,a%b);
}
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int num=sc.nextInt();
int power=sc.nextInt();
int[] arr=new int[num];
for(int i=0;i<num;i++){
arr[i]=sc.nextInt();
}
for(int i=0;i<num;i++){
if(power>=arr[i]){
power=power+arr[i];
}else{
power+=gcd(power,arr[i]);
}
}
System.out.println(power);
}
}
}