Skip to content

Instantly share code, notes, and snippets.

@Sumolari
Last active August 29, 2015 14:17
Show Gist options
  • Save Sumolari/cf7c1e78ef9049a52161 to your computer and use it in GitHub Desktop.
Save Sumolari/cf7c1e78ef9049a52161 to your computer and use it in GitHub Desktop.
12184
#include <iostream>
#include <vector>
#define INFINITY 9E18
#define IMPOSSIBLE "impossible"
using namespace std;
typedef vector<long long> vll;
long long GCD(long long a, long long b) {
long long c;
while (a != 0) {
c = a; a = b % a; b = c;
}
return b;
}
int main() {
int T;
int C;
int aux;
long long minSerial;
bool possible;
long long N;
long long maxComunDivisor;
long long maxA10;
int c;
int i;
int t;
cin >> T;
for (t = 0; t < T; t++) {
cin >> C;
maxA10 = 0;
minSerial = INFINITY;
vll serials(C, 0);
for (c = 0; c < C; c++) {
for (i = 0; i < 9; i++) {
cin >> aux;
serials[c] += aux;
}
cin >> aux;
serials[c] -= aux;
if (aux > maxA10) maxA10 = aux;
if (serials[c] < minSerial) minSerial = serials[c];
}
// Caso base 1: min <= 1.
if (minSerial <= 1) {
cout << IMPOSSIBLE << endl;
} else {
maxComunDivisor = serials[0];
for (c = 1; c < C; c++) {
maxComunDivisor = GCD(maxComunDivisor, serials[c]);
}
possible = (maxComunDivisor > 1 && maxComunDivisor > maxA10);
if (!possible) {
cout << IMPOSSIBLE << endl;
} else {
cout << maxComunDivisor << endl;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment