题解 | #最大公约数1#
最大公约数1
https://www.nowcoder.com/practice/021010dda9f04900a86738931a5600a4
#include <bits/stdc++.h> using namespace std; int GCD(int a, int b) { if (b == 0)return a; else return GCD(b, a % b); } int main() { int n; while (cin >> n) { int maxNum = INT_MIN; int minNum = INT_MAX; while (n--) { int temp; cin >> temp; if (temp > maxNum)maxNum = temp; if (temp < minNum)minNum = temp; } //求最大公约数 cout << minNum << " " << maxNum << " " << GCD(minNum, maxNum) << endl; } } // 64 位输出请用 printf("%lld")
GCD