結果

問題 No.2244 Integer Complete
ユーザー 👑 NachiaNachia
提出日時 2023-03-11 16:16:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 5,974 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 91,332 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-18 06:31:10
合計ジャッジ時間 3,020 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,940 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 2 ms
6,944 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 7 ms
6,940 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 5 ms
6,940 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 5 ms
6,944 KB
testcase_33 AC 3 ms
6,940 KB
testcase_34 AC 4 ms
6,940 KB
testcase_35 AC 6 ms
6,940 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 5 ms
6,944 KB
testcase_41 AC 5 ms
6,940 KB
testcase_42 AC 5 ms
6,940 KB
testcase_43 WA -
testcase_44 AC 5 ms
6,944 KB
testcase_45 AC 5 ms
6,940 KB
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 AC 4 ms
6,940 KB
testcase_50 WA -
testcase_51 AC 6 ms
6,944 KB
testcase_52 WA -
testcase_53 AC 5 ms
6,940 KB
testcase_54 AC 5 ms
6,940 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.cpp: In function 'int main()':
Main.cpp:30:15: warning: overflow in conversion from 'i64' {aka 'long long int'} to 'int' changes value from '1001001001001001001' to '1551474729' [-Woverflow]

ソースコード

diff #

#line 1 "Main.cpp"

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
#line 2 "nachia\\math\\prime-sieve-explicit.hpp"

#line 5 "nachia\\math\\prime-sieve-explicit.hpp"
#include <cassert>
#line 7 "nachia\\math\\prime-sieve-explicit.hpp"


namespace nachia{

namespace prime_sieve_explicit_internal{
    std::vector<bool> isprime = { false }; // a[x] := isprime(2x+1)

    void CalcIsPrime(int z){
        if((int)isprime.size() *2+1 < z+1){
            int new_z = isprime.size();
            while(new_z*2+1 < z+1) new_z *= 2;
            z = new_z-1;
            isprime.resize(z+1, true);
            for(int i=1; i*(i+1)*2<=z; i++) if(isprime[i]){
                for(int j=i*(i+1)*2; j<=z; j+=i*2+1) isprime[j] = false;
            }
        }
    }
    
    std::vector<int> prime_list = {2};
    int prime_list_max = 0;

    void CalcPrimeList(int z){
        while((int)prime_list.size() < z){
            if((int)isprime.size() <= prime_list_max + 1) CalcIsPrime(prime_list_max + 1);
            for(int p=prime_list_max+1; p<(int)isprime.size(); p++){
                if(isprime[p]) prime_list.push_back(p*2+1);
            }
            prime_list_max = isprime.size() - 1;
        }
    }

    void CalcPrimeListUntil(int z){
        if(prime_list_max < z){
            CalcIsPrime(z);
            for(int p=prime_list_max+1; p<(int)isprime.size(); p++){
                if(isprime[p]) prime_list.push_back(p*2+1);
            }
            prime_list_max = isprime.size() - 1;
        }
    }

}


bool IsprimeExplicit(int n){
    using namespace prime_sieve_explicit_internal;
    if(n == 2) return true;
    if(n % 2 == 0) return false;
    CalcIsPrime(n);
    return isprime[(n-1)/2];
}

int NthPrimeExplicit(int n){
    using namespace prime_sieve_explicit_internal;
    CalcPrimeList(n);
    return prime_list[n];
}

int PrimeCountingExplicit(int n){
    using namespace prime_sieve_explicit_internal;
    if(n < 2) return 0;
    CalcPrimeListUntil(n);
    auto res = std::upper_bound(prime_list.begin(), prime_list.end(), n) - prime_list.begin();
    return (int)res;
}

// [l, r)
std::vector<bool> SegmentedSieveExplicit(long long l, long long r){
    assert(0 <= l); assert(l <= r);
    long long d = r - l;
    if(d == 0) return {};
    std::vector<bool> res(d, true);
    for(long long p=2; p*p<=r; p++) if(IsprimeExplicit(p)){
        long long il = (l+p-1)/p, ir = (r+p-1)/p;
        if(il <= p) il = p;
        for(long long i=il; i<ir; i++) res[i*p-l] = false;
    }
    if(l < 2) for(long long p=l; p<2 && p<r; p++) res[l-p] = false;
    return res;
}


} // namespace nachia
#line 2 "nachia\\math\\floor-of-kth-root.hpp"

#line 4 "nachia\\math\\floor-of-kth-root.hpp"

namespace nachia{

namespace internal{

// mod 2^64
constexpr unsigned long long PowerOfULongLong(unsigned long long a, unsigned long long i){
    unsigned long long res = 1;
    while(i){ if(i&1){ res *= a; } i /= 2; a *= a; }
    return res;
}

}

unsigned long long FloorOfKthRoot(unsigned long long real, unsigned long long k){
    using u64 = unsigned long long;
    assert(k != 0);
    if(real <= 1) return real;
    if(k >= 64) return 1;
    if(k == 1) return real;
    struct Precalc{
        // a^i <= x
        static constexpr bool lesseq(u64 a, int i, u64 x) {
            if (a == 0) return true;
            for(int j=0; j<i; j++) x /= a;
            return x >= 1;
        }
        unsigned long long BORDER[64];
        constexpr Precalc() : BORDER() {
            for (int idx = 2; idx <= 63; idx++) {
                u64 l = 0, r = 1ull << 33;
                while (l + 1 < r) {
                    u64 m = (l + r) / 2;
                    if (lesseq(m, idx, ~0ull)) l = m;
                    else r = m;
                }
                BORDER[idx] = r;
            }
        };
    };
    constexpr Precalc precalc;
    u64 l = 0, r = precalc.BORDER[k];
    while (l + 1 < r) {
        u64 m = (l + r) / 2;
        if(internal::PowerOfULongLong(m, k) <= real) l = m;
        else r = m;
    }
    return l;
}

unsigned long long CeilOfKthRoot(unsigned long long real, unsigned long long k){
    if(real <= 1) return real;
    if(k >= 64) return 2;
    if(k == 1) return real;
    unsigned long long x = FloorOfKthRoot(real, k);
    if(internal::PowerOfULongLong(x, k) != real) x++;
    return x;
}

} // namespace nachia
#line 9 "Main.cpp"
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;

int main(){
    int N, M; cin >> N >> M;
    vector<int> A(40000);
    vector<int> B(40000);
    rep(i,N){ int a; cin >> a; A[a] = 1; }
    rep(i,M){ int a; cin >> a; B[a] = 1; }

    if(A[1] == 0 || B[1] == 0){ cout << "1\n"; return 0; }
    
    int mex = 1;
    while(A[mex] == 1 || B[mex]) mex++;
    int ans = INF;
    int ansmin = mex * mex;
    auto tab = nachia::SegmentedSieveExplicit(mex*mex, (mex+1)*(mex+1));
    rep(i,tab.size()) if(tab[i]){ ans = mex*mex+i; break; }

    vector<int> Flag(ans - ansmin + 1);

    auto checkPlayable = [&](int a, int b) -> void {
        int a1 = nachia::FloorOfKthRoot(a, 2) - 1;
        int b1 = nachia::FloorOfKthRoot(b, 2) - 1;
        // if playable
        if((A[a1] && B[b1]) || (A[b1] && B[a1])) Flag[a*b-ansmin] = 1;
    };

    for(int d=2; d*d<=ans; d++){
        // ansmin <= d * e < ans を探索
        int el = (int)((double)(ansmin - 1) / (double)d) + 1;
        int er = (int)((double)(ans - 1) / d);
        for(i64 e=el; e<=er; e++) checkPlayable(d, e);
    }

    for(int i=0; i<(int)Flag.size(); i++) if(Flag[i] == 0){ ans = ansmin + i; break; }

    cout << ans << '\n';
    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0