Last active
August 29, 2015 14:17
-
-
Save Sumolari/cf7c1e78ef9049a52161 to your computer and use it in GitHub Desktop.
12184
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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