Created
September 16, 2013 07:12
-
-
Save phonism/6577522 to your computer and use it in GitHub Desktop.
SGU 499. Greatest Greatest Common Divisor
http://acm.sgu.ru/problem.php?contest=0&problem=499
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 <cstdio> | |
#include <cstring> | |
#include <algorithm> | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
const int maxn = 1000010; | |
int n, maxx, a[100100], pos[maxn]; | |
void init() { | |
scanf("%d", &n); | |
for (int i = 1; i <= n; i++) { | |
scanf("%d", &a[i]); | |
pos[a[i]] = i; | |
maxx = max(a[i], maxx); | |
} | |
maxx += 2; | |
} | |
bool check(int x) { | |
int res = 0; | |
for (int i = x; i < maxx; i += x) { | |
if (res > 1) break; | |
if (pos[i]) res++; | |
} | |
if (res > 1) | |
return true; | |
else | |
return false; | |
} | |
void work() { | |
for (int i = maxx - 2; i >= 1; i--) { | |
if (check(i) == true) { | |
printf("%d\n", i); | |
return ; | |
} | |
} | |
} | |
int main() { | |
init(); | |
work(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment