一、题目
Problem #3985 - ECNU Online Judge
二、思路
第一眼还以为是最基本的欧几里得,然后一个劲地在那里找合适的一组整数,找了一会没找到,后面直接用随机查找一下子找到了
三、代码
import sun.misc.GC;import java.util.Random;
import java.util.Scanner;public class Main {public static void main(String[] args) {while (true){int[] a = new int[5];Random random = new Random();for (int i = 0; i < 3; i++) {a[i]= random.nextInt(50)+50;System.out.print(a[i]+" ");}int x=_gcd(a[0],a[1]);int y=_gcd(x,a[2]);System.out.println();if(y!= GCD(3,a)){System.out.println("False");System.out.println(y);System.out.println(GCD(3,a));break;}}}public static int GCD(int n, int a[]) {int Min = _gcd(a[0], a[1]);for (int i = 0; i < n; i++)for (int j = i + 1; j < n; j++)Min = Math.min(Min, _gcd(a[i], a[j]));return Min;}public static int _gcd(int a, int b) {return b == 0 ? a : _gcd(b, a % b);}
}