1179 the largest greatest common divisortitle Source: SGUbase time limit: 1 seconds space limit: 131072 KB Score: 40 Difficulty: 4-level algorithm problemgive n positive integers to find the maximum value of greatest common divisor between n number 22. For example: N = 4, 4 numbers: 9 15 25 16, 22 the maximum value between greatest common divisor is 15 with 25 greatest common divisor 5. Input
Line 1th: A number n, which represents the number of input positive integers. (2 <= N <= 50000) 2-n + 1 lines: 1 numbers per line, corresponding positive integers for input. (1 <= s[i] <= 1000000)
Output
The maximum value of greatest common divisor between output 22.
Input Example
49152516
Output Example
5
/*51nod 1179 the largest greatest common divisor gives you the number of n, ask them the maximum number of conventions between 22 to find all the n number of factors and record the number of occurrences, and then find the NUM >= 2 (two numbers have this factor) the maximum value can be HHH-2016/05/26 21:57*/#include <iostream> #include <vector> #include <cstring> #include <string> #include < cstdio> #include <queue> #include <cmath> #include <algorithm> #include <functional># Include <map>using namespace std; #define Lson (i<<1) #define Rson ((i<<1) | |) typedef LONG LONG ll;using namespace Std;const ll maxn = 1000010;const double PI = 3.1415926;const double eps = 1e-15;int n;int num[maxn];int ans;int Main () {//freopen ("In.txt", "R", stdin); int n,x; scanf ("%d", &n); int Max = 0; for (int t = 0;t < n;t++) {scanf ("%d", &x); max = max (X,max); num[1]++; num[x]++; for (int i = 2; i*i <= x; i++) if (x%i = = 0) {num[i]++; num[x/i]++; }} for (int i = Max;i >= 1;i--) {if (Num[i] >= 2) {ans = i; Break }} printf ("%d\n", ans); return 0;}
51nod 1179 the largest greatest common divisor