#include <iostream>
#include <vector>
int main() {
unsigned long long n;
unsigned long long k;
std::cin >> n;
std::cin >> k;
std::vector<int> primes;
for (unsigned long long i = 0; i < n; ++i) {
int a;
std::cin >> a;
primes.push_back(a);
}
for (unsigned long long j = n - 1; j > 0; j--) {
if (primes.operator[](j) > k) {
primes.erase(primes.begin() + j - 1);
}
}
unsigned long long max = k;
while (true) {
std::vector<unsigned long long> options;
std::vector<unsigned long long>::iterator it;
options.push_back(max);
while (options.size() != 0) {
it = options.begin();
int current = *it;
options.erase(it);
if (current == 1) {
std::cout << max;
return 0;
}
for (int i = 0; i < primes.size(); ++i) {
if (current % primes.operator[](i) == 0) {
options.push_back(current / primes.operator[](i));
}
}
}
max--;
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #include <iostream> #include <vector> int main() { unsigned long long n; unsigned long long k; std::cin >> n; std::cin >> k; std::vector<int> primes; for (unsigned long long i = 0; i < n; ++i) { int a; std::cin >> a; primes.push_back(a); } for (unsigned long long j = n - 1; j > 0; j--) { if (primes.operator[](j) > k) { primes.erase(primes.begin() + j - 1); } } unsigned long long max = k; while (true) { std::vector<unsigned long long> options; std::vector<unsigned long long>::iterator it; options.push_back(max); while (options.size() != 0) { it = options.begin(); int current = *it; options.erase(it); if (current == 1) { std::cout << max; return 0; } for (int i = 0; i < primes.size(); ++i) { if (current % primes.operator[](i) == 0) { options.push_back(current / primes.operator[](i)); } } } max--; } } |
English