/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 576.0 KiB
#2 Accepted 2ms 580.0 KiB
#3 Accepted 2ms 580.0 KiB
#4 Accepted 2ms 576.0 KiB
#5 Accepted 2ms 580.0 KiB
#6 Accepted 2ms 604.0 KiB
#7 Accepted 2ms 572.0 KiB
#8 Accepted 2ms 532.0 KiB
#9 Accepted 2ms 532.0 KiB
#10 Accepted 2ms 532.0 KiB
#11 Accepted 3ms 612.0 KiB
#12 Accepted 3ms 484.0 KiB
#13 Accepted 3ms 440.0 KiB
#14 Accepted 3ms 616.0 KiB
#15 Accepted 3ms 580.0 KiB
#16 Accepted 2ms 576.0 KiB
#17 Accepted 3ms 552.0 KiB
#18 Accepted 2ms 532.0 KiB
#19 Accepted 2ms 608.0 KiB

Code

#include <bits/stdc++.h>

#ifdef LOCAL
#include "template.cpp.h"
#else
#define debug(...)
#endif

//#define int long long
using namespace std;
#define cinv(v) for (auto &it:v) cin>>it;
#define coutv(v) for (auto &it:v) cout<< it<<' '; cout<<'\n';

const int N = 105;
vector<int> divisors[N];
int cnt[N], lcm_[N][N];
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

void shelby() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        for (auto &it: divisors[v[i]]) cnt[it]++;
    }
    int ans = 0;
    for (int random = 1; random <= 20; ++random) {
        int x = v[rng() % n], y = v[rng() % n];
        for (auto &i: divisors[x]) {
            for (auto &j: divisors[y]) {
                if (i == j) {
                    if (cnt[i] == n) ans = max(ans, 2 * i);
                    continue;
                }
                int a = cnt[i], b = cnt[j], l = lcm_[min(i, j)][max(i, j)], c = (l < N ? cnt[l] : 0);
                if (a < b) swap(a, b);
                int extra = a - n / 2 - (n % 2);
                c -= extra;
                if (extra < 0 || c < 0) continue;
                b -= c;
                if (b == n / 2) ans = max(ans, i + j);
            }
        }
    }
    cout << ans << '\n';
    for (int i = 1; i < N; ++i) cnt[i] = 0;
}

signed main() {
    cin.tie(0)->ios_base::sync_with_stdio(0);
    for (int i = 1; i < N; ++i) {
        for (int j = i; j < N; j += i) divisors[j].push_back(i);
    }
    for (int i = 1; i < N; ++i) {
        for (int j = i; j < N; ++j) lcm_[i][j] = lcm(i, j);
    }
    int t = 1;
    cin >> t;
    for (int _ = 1; _ <= t; ++_) {
//        cout << "Case " << _ << ": ";
        shelby();
    }
}

Information

Submit By
Type
Submission
Problem
P1076 Even Odd GCD (Easy Version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-17 12:07:52
Judged At
2024-11-11 03:08:26
Judged By
Score
100
Total Time
3ms
Peak Memory
616.0 KiB