Advertisement
Alexvans

Untitled

Aug 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #define MAX 1000002
  3. using namespace std;
  4.  
  5. long v[MAX];
  6.  
  7. int main() {
  8.     ios_base::sync_with_stdio(0);
  9.     cin.tie(0);
  10.     cout.tie(0);
  11.     long n;
  12.     cin >> n;
  13.     for(int i = 0; i < n; ++i) {
  14.         long test;
  15.         cin >> test;
  16.         v[test]++;
  17.     }
  18.     for(int i = MAX; i >= 1; --i) {
  19.         long a = 0, b = 0;
  20.         for(int j = MAX-(MAX%i); j > 0; j -= i) {
  21.             if(v[j] && !a) {
  22.                 if(v[j] > 1) {
  23.                     a = j;
  24.                     b = j;
  25.                     break;
  26.                 }
  27.                 else a = j;
  28.             }
  29.             else if(v[j] && a && !b) {
  30.                 b = j;
  31.                 break;
  32.             }
  33.         }
  34.         if(a && b) {
  35.             (a%b == 0) ? cout << a : cout << ((a*b)/i);
  36.             return 0;
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement