题解 | #小易的升级之路#欧德里奇计算最大公约数
小易的升级之路
https://www.nowcoder.com/practice/fe6c73cb899c4fe1bdd773f8d3b42c3d
import java.util.Scanner; /** 2023/3/2 14:07 */ public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { Integer num = sc.nextInt(); Integer init = sc.nextInt(); Integer[] mons = new Integer[num]; for (int i=0;i<num;i++){ mons[i] = sc.nextInt(); } calcute(num, init, mons); } } private static void calcute(int num, int init, Integer[] mons) { for (int i = 0; i < num; i++) { int mon = mons[i]; if (init >= mon) { init += mon; } else { init += odlj(init, mon); } } System.out.println(init); } public static int odlj(int n1, int n2) { int m = Math.max(n1, n2); int n = Math.min(n1, n2); while (m % n != 0) { int temp = m % n; m = n; n = temp; } return n; } }