Skip to content

Instantly share code, notes, and snippets.

@sofhiasouza
Last active October 24, 2019 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sofhiasouza/7e045691ebbafc258fffad10a5af3336 to your computer and use it in GitHub Desktop.
Save sofhiasouza/7e045691ebbafc258fffad10a5af3336 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
if(b == 0) return a;
return gcd(b, a%b);
}
int main()
{
int n;
cin >> n; //leio o n
while(n--) //rodo os n casos
{
int f1, f2;
cin >> f1 >> f2; //leio o f1 e o f2
if(f1 < f2) swap(f1, f2); //coloco f1 como o maior e f2 como o menor
int resp = gcd(f1, f2); //calculo o mdc de f1 e f2
cout << resp << "\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment