/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 1ms 324.0 KiB
#3 Wrong Answer 2ms 532.0 KiB
#4 Accepted 2ms 564.0 KiB
#5 Accepted 2ms 324.0 KiB
#6 Accepted 2ms 564.0 KiB
#7 Accepted 2ms 532.0 KiB
#8 Accepted 3ms 320.0 KiB
#9 Accepted 3ms 532.0 KiB
#10 Accepted 5ms 320.0 KiB
#11 Accepted 13ms 324.0 KiB
#12 Wrong Answer 13ms 320.0 KiB
#13 Wrong Answer 7ms 564.0 KiB
#14 Wrong Answer 8ms 320.0 KiB
#15 Accepted 8ms 556.0 KiB
#16 Accepted 8ms 532.0 KiB
#17 Accepted 8ms 532.0 KiB
#18 Accepted 7ms 320.0 KiB
#19 Accepted 6ms 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++) {
  int cnt = 0, gcd1 = 0, gcd2 = 0;
  for(int j = 1; j <= n; j++) {
    if(ar[j] % i == 0 && cnt < min(even, odd)) {
      cnt++;
    }
    else {
      gcd1 = __gcd(gcd1, ar[j]);
    }
  }


  if(cnt  == min(even, odd)) {
    ans = max (ans, i + gcd1);
  }
 }
 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:13:52
Judged At
2024-10-03 13:28:05
Judged By
Score
73
Total Time
13ms
Peak Memory
564.0 KiB