結果

問題 No.2244 Integer Complete
ユーザー jiangly
提出日時 2023-03-11 02:01:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,496 bytes
コンパイル時間 2,123 ms
コンパイル使用メモリ 197,812 KB
最終ジャッジ日時 2025-02-11 09:48:47
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 60
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using i64 = long long;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N, M;
    std::cin >> N >> M;
    
    std::vector<int> A(N), B(M);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i];
    }
    for (int i = 0; i < M; i++) {
        std::cin >> B[i];
    }
    
    if (A[0] != 1 || B[0] != 1) {
        std::cout << 1 << "\n";
        return 0;
    }
    
    auto check = [&](auto &A, int x) {
        return std::binary_search(A.begin(), A.end(), int(std::sqrt(x)));
    };
    
    for (int x = 2, i = 0, j = 0; ; x++) {
        while (i < N && A[i] < x) {
            i++;
        }
        while (j < M && B[j] < x) {
            j++;
        }
        if ((i == N || A[i] != x) && (j == M || B[j] != x)) {
            for (int n = x * x; ; n++) {
                bool ok = false;
                for (int x = 1; x * x <= n; x++) {
                    if (n % x != 0) {
                        continue;
                    }
                    if (check(A, x) && check(B, n / x)) {
                        ok = true;
                        break;
                    }
                    if (check(A, n / x) && check(B, x)) {
                        ok = true;
                        break;
                    }
                }
                if (!ok) {
                    std::cout << n << "\n";
                    return 0;
                }
            }
        }
    }
    
    return 0;
}
0