首页 > 试题广场 >

最大公约数1

[编程题]最大公约数1
  • 热度指数:9036 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
读入n个正整数,求出这n个数的最小值、最大值以及它们两的最大公约数,并输出。输入中第一行为n,接下来为n个大于零的整数。

输入描述:
第一行为n。第二行是n个大于零的整数,用空格隔开。


输出描述:
分别输出最小值、最大值和它们两的最大公约数,用空格隔开。
示例1

输入

3
4 8 6

输出

4 8 4
头像 鱼儿恋上水
发表于 2020-03-28 11:50:58
执行速度(从快->慢):__gcd()algorithm库函数>gcd更相减损术与移位结合>gcd1更相减损术>gcd2辗转相除法 #include <iostream> #include <cstdio> #include <climits&g 展开全文
头像 牛客440904392号
发表于 2024-08-12 01:27:21
#include <bits/stdc++.h> //#include <iostream> //#include <vector> //#include <numeric> //#include <algorithm> using nam 展开全文
头像 笑川不吃香菜
发表于 2024-03-12 19:04:48
#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() { 展开全文
头像 给我就亿下
发表于 2023-03-24 21:01:36
#include <iostream> #include <algorithm> using namespace std; int Divisor (int a, int b){ if (b == 0){ return a; }else if (b > a) 展开全文
头像 不学习就会变废物
发表于 2025-03-06 21:12:11
#include <iostream> #include <stdlib.h> using namespace std; void gcd(int a, int b) { int c; c = a % b; while (c != 0) { 展开全文
头像 牛客737132239号
发表于 2025-03-21 10:26:10
#include<stdio.h> int main(){ int n; while(scanf("%d",&n) != EOF){ int a[n]; for(int i= 0 ;i<n;i++){ scanf("%d" 展开全文
头像 rainman_
发表于 2023-03-22 08:48:26
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <stack> #include <map> #incl 展开全文
头像 牛客596495425号
发表于 2025-03-20 13:40:54
#include <iostream> #include<algorithm> #include<vector> using namespace std; int gcd(int a,int b){ return b?gcd(b,a%b):a; } i 展开全文
头像 cyber1026
发表于 2024-03-07 16:09:38
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main(){ int n; int a[100000000]; while( cin 展开全文
头像 ☆☆浮生若梦
发表于 2021-02-03 16:28:40
#include<bits/stdc++.h> using namespace std; int f(int b,int c) { if(c==0) return b; else return f(c,b%c); } int main() { in 展开全文

问题信息

上传者:小小
难度:
35条回答 4265浏览

热门推荐

通过挑战的用户

查看代码
最大公约数1