题解 | 最大公约数1

最大公约数1

https://www.nowcoder.com/practice/021010dda9f04900a86738931a5600a4

#include <iostream>
#include <numeric>
#include <climits>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    while(cin >> n){
        int xmax = INT_MIN;
        int xmin = INT_MAX;
        int x;
        for(int i = 0; i < n; i++){
            cin >> x;
            xmax = max(x, xmax);
            xmin = min(x, xmin);
        }
        int a = gcd(xmax, xmin);
        cout << xmin << " " << xmax << " " << a << "\n";
    }
    return 0;
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务