#include <iostream> #include <cstddef> #include <vector> using namespace std; bool ok(uint16_t i, const vector<uint32_t> &p) { bool end = false; while (i > 1 && !end) { // cerr << "i=" << i << endl; end = true; for (auto pi : p) { // cerr << "pi=" << pi << endl; if (i % pi == 0) { // cerr << "div" << endl; end = false; i /= pi; } // else cerr << "nodiv" << endl; } } return i <= 1; } int main() { ios_base::sync_with_stdio(0); uint64_t k, N; cin >> k >> N; vector<uint32_t> v(k); for (uint32_t i = 0; i < k; ++i) cin >> v[i]; for (uint64_t i = N; i >= 0; --i) { // cerr << "i=" << i << endl; if (ok(i, v)) { cout << i << endl; break; } } return 0; }
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 46 47 48 49 50 51 | #include <iostream> #include <cstddef> #include <vector> using namespace std; bool ok(uint16_t i, const vector<uint32_t> &p) { bool end = false; while (i > 1 && !end) { // cerr << "i=" << i << endl; end = true; for (auto pi : p) { // cerr << "pi=" << pi << endl; if (i % pi == 0) { // cerr << "div" << endl; end = false; i /= pi; } // else cerr << "nodiv" << endl; } } return i <= 1; } int main() { ios_base::sync_with_stdio(0); uint64_t k, N; cin >> k >> N; vector<uint32_t> v(k); for (uint32_t i = 0; i < k; ++i) cin >> v[i]; for (uint64_t i = N; i >= 0; --i) { // cerr << "i=" << i << endl; if (ok(i, v)) { cout << i << endl; break; } } return 0; } |