Skip to content

Instantly share code, notes, and snippets.

@fredbr

fredbr/mdc.cpp Secret

Created May 29, 2018 23:11
Show Gist options
  • Save fredbr/97dc6e0b8eb4ba487362bcabed9ba427 to your computer and use it in GitHub Desktop.
Save fredbr/97dc6e0b8eb4ba487362bcabed9ba427 to your computer and use it in GitHub Desktop.
// solucao de Davi Gabriel
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b){
if(b == 0) return a;
if(a == 0) return b;
int x = min(a, b);
int y = max(a, b);
return gcd(x, y%x);
}
int num[100100];
int main() {
int n, mdc = 0;
cin >> n;
for(int i = 0; i < n; i++){
cin >> num[i];
mdc = gcd(mdc, num[i]);
}
cout << mdc << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment