/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1422ms 112.387 MiB
#2 Accepted 1442ms 112.281 MiB
#3 Accepted 1405ms 112.332 MiB
#4 Accepted 1439ms 112.355 MiB
#5 Accepted 1428ms 112.316 MiB
#6 Accepted 1510ms 112.391 MiB
#7 Accepted 1430ms 112.266 MiB
#8 Accepted 1490ms 112.363 MiB
#9 Accepted 1525ms 112.211 MiB
#10 Accepted 1672ms 112.402 MiB
#11 Accepted 1709ms 112.23 MiB
#12 Accepted 1717ms 112.395 MiB
#13 Accepted 1697ms 112.395 MiB
#14 Accepted 1710ms 112.215 MiB
#15 Accepted 1693ms 112.164 MiB
#16 Accepted 1585ms 112.223 MiB
#17 Accepted 1535ms 112.211 MiB
#18 Accepted 1514ms 112.363 MiB

Code

// BISMILLAH

#include "bits/stdc++.h"

#define fastIO std::ios::sync_with_stdio(0);std::cin.tie(0)
#define ll long long int
#define flush fflush(stdout)
// #define int ll

using pii = std::pair<int,int>;

const int MOD = 1000000007;
// const int MOD = 998244353;
const int mxN = 1000005, inf = 1000000005;

std::vector<std::vector<int>> factors(mxN);

void pre() {
    for (int i = 1; i < mxN; i++) {
        for (int j = i; j < mxN; j += i) {
            factors[j].push_back(i);
        }
    }
}

signed main()
{
    // fastIO;
	int testCases=1;
	scanf("%lld",&testCases);
	// std::cin >> testCases;

    pre();

    for (int T = 1; T <= testCases; T++) {
        int N, x;
        scanf("%d%d", &N, &x);
        std::map<int, ll> val;
        for (int i = 0, x; i < N; i++) {
            scanf("%d", &x);
            for (auto j : factors[x]) {
                val[j] += x;
            }
        }
        int ans, lst = 0;
        ll value = LLONG_MAX;
        for (auto i : val) {
            if (i.first > x)
                break;
            if (lst+1 != i.first) {
                ans = lst + 1;
                value = 0;
                break;
            }
            if (i.second < value) {
                value = i.second;
                ans = i.first;
            }
            lst = i.first;
        }
        if (value && lst < x) {
            ans = lst + 1;
        }
        printf("%d\n", ans);
    }
	
	return 0;
}

/*

*/

Information

Submit By
Type
Submission
Problem
P1039 Prince Roy, the undisputed ruler of the world
Language
C++11 (G++ 13.2.0)
Submit At
2024-05-07 12:06:10
Judged At
2024-11-11 03:30:54
Judged By
Score
100
Total Time
1717ms
Peak Memory
112.402 MiB