/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 56ms 12.605 MiB
#2 Accepted 56ms 11.707 MiB
#3 Accepted 53ms 11.992 MiB
#4 Accepted 56ms 13.188 MiB
#5 Accepted 57ms 12.926 MiB
#6 Accepted 62ms 11.523 MiB
#7 Accepted 49ms 11.449 MiB
#8 Accepted 59ms 13.09 MiB
#9 Accepted 64ms 13.137 MiB
#10 Accepted 56ms 11.93 MiB
#11 Accepted 61ms 12.895 MiB
#12 Accepted 53ms 13.629 MiB
#13 Accepted 61ms 11.48 MiB
#14 Accepted 56ms 11.797 MiB
#15 Accepted 65ms 13.32 MiB
#16 Accepted 56ms 11.754 MiB
#17 Accepted 102ms 13.75 MiB
#18 Accepted 64ms 13.219 MiB
#19 Accepted 66ms 11.773 MiB
#20 Accepted 70ms 12.578 MiB
#21 Accepted 68ms 12.297 MiB
#22 Accepted 72ms 12.996 MiB
#23 Accepted 76ms 12.102 MiB
#24 Accepted 73ms 13.145 MiB
#25 Accepted 77ms 11.52 MiB
#26 Accepted 71ms 13.27 MiB
#27 Accepted 74ms 13.02 MiB
#28 Accepted 74ms 12.07 MiB
#29 Accepted 79ms 13.52 MiB
#30 Accepted 79ms 13.262 MiB
#31 Accepted 87ms 13.875 MiB
#32 Accepted 69ms 12.312 MiB
#33 Accepted 63ms 13.348 MiB
#34 Accepted 63ms 12.723 MiB
#35 Accepted 102ms 12.828 MiB

Code

///**Bismillahir Rahmanir Raheem**
///**       Mizanul Hoque       **
///**           IIUC            **
/// ###############################
#include <bits/stdc++.h>
using namespace std;
/// POLICY BASED DATA STRUCTURE..
/// order_of_key return number of element which are strictly greater/smaller than x..
/// find_by_order return ans iterator corresponding to the xth position of the set..

// #include<ext/pb_ds/assoc_container.hpp>
//  #include<ext/pb_ds/tree_policy.hpp>
//  using namespace __gnu_pbds;
//  #define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>

#define faster                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define sz(n) (int)(n).size()
#define eps 1e-10

#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;

#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define max3(a, b, c) max(c, max(a, b))
#define max4(a, b, c, d) max(d, max(c, max(a, b)))

#define pi 2 * acos(0) /// acos(-1.0)
#define deg_to_rad(x) ((x) * ((2 * acos(0)) / 180.0))
#define rad_to_deg(x) ((x) * (180.0 / (2 * acos(0))))

#define fi first
#define sc second
#define mp make_pair
#define __lcm(a, b) (a / __gcd(a, b) * b*1LL)

typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int M = 1e9 + 7;
const int N = 200020;

// ll n,m,i,k,h;

vector<ll> prime_divisor[N];
int vis[N];
vector<int> edge[N];

bool cmp(pair<ll, ll> p1, pair<ll, ll> p2)
{
    return p1.fi < p2.fi;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll gen_random(ll l, ll r)
{
    return uniform_int_distribution<ll>(l, r)(rng);
}

// gen_random(l, r); // generates a random integer between l and r

const int lim = 100005;
vector<int> divisors[lim];
void sieve()
{
    for (int i = 1; i < lim; i++)
    {
        for (int j = i; j < lim; j += i)
        {
            divisors[j].push_back(i);
        }
    }
}

int freq[lim]; // to count the frequency of each element
int tot[lim];  // tot[i]->gcd count of i

void solve()
{
    ll i, j, k, n, m, p, q, x, y, z, u, v, l, r, mod = 1e9 + 7, mx, mn, mx1, mn1, cnt1;
    cin >> n;
    ll a[n + 5];
    ll gc = 0;
    memset(freq, 0, sizeof(freq));
    memset(tot, 0, sizeof(tot));
    for (i = 0; i < n; i++)
    {
        cin >> a[i];
        gc = __gcd(gc, a[i]);
        freq[a[i]]++;
    }
    for (i = 1; i < lim; i++)
    {
        for (j = i; j < lim; j += i)
        {
            tot[i] += freq[j];
        }
    }
    int ans=2*gc;
    assert(n > 0);
    for(k=0;k<10;k++)
    {
        int x=a[rng()%n];
        int y=a[rng()%n];
        for(int i: divisors[x])
        {
           for(int j: divisors[y])
           {
               if(i==j)continue;
               ll lc=(1LL*i*j)/__gcd(i,j);
               if(lc>=lim)lc=0;
               assert(lc < lim);
               if(tot[i]+tot[j]-tot[lc]!=n)continue;
                p=tot[i];
                q=tot[j];
                if(p<q)swap(p,q);
                if(p>=(n+1)/2 && q>=(n/2))
                {
                    ans=max(ans,i+j);
                }
           }
        }
    }
    cout<<ans<<endl;
}

int main()
{
    faster;
    ll tc = 1;
    cin >> tc;
    sieve();
    for (ll t = 1; t <= tc; t++)
    {
        /// cout<<"Case "<<t<<": ";
        solve();
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1077 Even Odd GCD (Hard Version)
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-06 13:12:29
Judged At
2024-09-06 13:12:29
Judged By
Score
100
Total Time
102ms
Peak Memory
13.875 MiB