Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: B. Even Modulo Pair
- // Contest: Codeforces - Codeforces Global Round 30 (Div. 1 + Div. 2)
- // URL: https://codeforces.com/contest/2164/problem/B
- // Memory Limit: 256 MB
- // Time Limit: 1000 ms
- //
- // Powered by CP Editor (https://cpeditor.org)
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #ifndef __DEBUG__
- #define dbg(...) 42
- #endif
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- namespace rngs = std::ranges;
- using ll = long long;
- using a2l = array<ll, 2>;
- using vl = vector<ll>;
- void solve()
- {
- ll n;
- cin >> n;
- vl a(n), ev, od;
- for (auto &x : a) {
- cin >> x;
- (x % 2 ? od : ev).push_back(x);
- }
- if (ev.size() >= 2) {
- cout << ev[0] << ' ' << ev[1] << '\n';
- return;
- }
- if (ev.size() != 0) {
- for (auto val : od) {
- ll x = min(ev[0], val), y = max(ev[0], val);
- if (y % x % 2 == 0) {
- cout << x << ' ' << y << '\n';
- return;
- }
- }
- }
- for (auto [x, y] : od | std::views::pairwise) {
- if (y % x % 2 == 0) {
- cout << x << ' ' << y << '\n';
- return;
- }
- }
- assert(od.size() < 40);
- for (ll i = 0; i < od.size(); ++i) {
- for (ll j = i + 1; j < od.size(); ++j) {
- ll x = od[i], y = od[j];
- if (y % x % 2 == 0) {
- cout << x << ' ' << y << '\n';
- return;
- }
- }
- }
- cout << -1 << '\n';
- }
- void solve1()
- {
- ll n, oc = 0;
- cin >> n;
- vl a(n);
- for (auto &x : a)
- cin >> x, oc += x % 2 == 0;
- if (oc >= 2) {
- ll x = -1, y = -1;
- for (ll i = 0; i < n; ++i)
- if (a[i] % 2 == 0) {
- if (x == -1)
- x = a[i];
- else
- y = a[i];
- }
- cout << x << ' ' << y << '\n';
- return;
- }
- for (auto y : a) {
- // 分块
- for (auto x : a) {
- if (x * x > y)
- break;
- if (y != x && y % x % 2 == 0) {
- cout << x << ' ' << y << '\n';
- return;
- }
- }
- for (ll i = 1; i * i <= y; i += 1) {
- if (y % 2 != i % 2)
- continue;
- ll lb = y / (i + 1), ub = y / i;
- auto it1 = lower_bound(a.begin(), a.end(), lb);
- auto it2 = upper_bound(a.begin(), a.end(), ub);
- if (it1 != a.end() && *it1 <= ub) {
- dbg(lb, ub, *it1);
- ll x = *it1;
- if (x > ub)
- continue;
- if (x == y)
- continue;
- if (y % x % 2 == 0) {
- cout << x << ' ' << y << '\n';
- return;
- }
- }
- }
- }
- cout << -1 << '\n';
- }
- int main(int argc, char **argv)
- {
- std::ios::sync_with_stdio(false);
- std::cin.tie(nullptr);
- ll t = 1;
- cin >> t;
- while (t--)
- solve();
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment