/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 324.0 KiB
#3 Accepted 9ms 532.0 KiB
#4 Accepted 11ms 532.0 KiB
#5 Accepted 13ms 560.0 KiB
#6 Accepted 13ms 500.0 KiB
#7 Accepted 11ms 556.0 KiB
#8 Accepted 11ms 532.0 KiB
#9 Accepted 11ms 532.0 KiB
#10 Accepted 13ms 532.0 KiB
#11 Accepted 22ms 552.0 KiB
#12 Accepted 34ms 552.0 KiB
#13 Accepted 20ms 532.0 KiB
#14 Accepted 22ms 532.0 KiB
#15 Accepted 22ms 556.0 KiB
#16 Accepted 15ms 324.0 KiB
#17 Accepted 21ms 532.0 KiB
#18 Accepted 16ms 532.0 KiB
#19 Accepted 14ms 532.0 KiB

Code

#include <bits/stdc++.h>
#define ll long long
#define endll '\n';
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;

const int mod = 1e9 + 7, N = 1e6;

void solve()
{
  int n;
  cin >> n;
  int ar[n + 3];
  for (int i = 1; i <= n; i++)
  {
    cin >> ar[i];
  }

  int even = n / 2, odd = n - even, ans = 0;

  for (int i = 1; i <= 100; i++)
  {

    for (int j = 1; j <= 100; j++)
    {
      int both = 0, first = 0, second = 0, flg = 0;
      for (int k = 1; k <= n; k++)
      {
        if (ar[k] % i == 0 && ar[k] % j == 0)
        {
          both++;
        }
        else if (ar[k] % i == 0)
        {
          first++;
        }
        else if (ar[k] % j == 0)
        {
          second++;
        }
        else
        {
          flg = 1;
          break;
        }
      }

      if (flg == 0)
      {
        if(first > even && first > odd) {
          continue;
        } 

        if(second > even && second > odd) {
          continue;
        }

        ans = max (ans, i + j);
      }
    }
  }
  cout << ans << endll;
}

int32_t main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t = 1;
  cin >> t;
  while (t--)
  {
    solve();
  }
  return 0;
}

Information

Submit By
Type
Submission
Problem
P1076 Even Odd GCD (Easy Version)
Contest
Bangladesh 2.0
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-16 16:24:57
Judged At
2024-08-16 16:24:57
Judged By
Score
100
Total Time
34ms
Peak Memory
560.0 KiB