题解 | #最大公约数1#
最大公约数1
https://www.nowcoder.com/practice/021010dda9f04900a86738931a5600a4
#include <iostream> #include <algorithm> using namespace std; int Divisor (int a, int b){ if (b == 0){ return a; }else if (b > a){ return Divisor(a, b % a); }else{ return Divisor(b, a % b); } } int main () { int n; while (cin >> n){ int arr[n]; for (int i = 0; i < n; i++){ cin >> arr[i]; } sort (arr, arr + n); cout << arr[0] << " " << arr[n - 1] << " " << Divisor(arr[0], arr[n - 1]) << endl; } return 0; }