#include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(false); long long int k, N; int p[100]; cin >> k >> N; for (int i = 0; i < k; ++i) { cin >> p[i]; } for (long long j = N; j > 0; --j) { long long candidate = j; for (int i = 0; i < k; ++i) { while(candidate % p[i] == 0) { candidate /= p[i]; } } const bool found = candidate==1; if(found) { cout << j << endl; return 0; } } cout << "NIE" << endl; 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 | #include <iostream> using namespace std; int main() { ios_base::sync_with_stdio(false); long long int k, N; int p[100]; cin >> k >> N; for (int i = 0; i < k; ++i) { cin >> p[i]; } for (long long j = N; j > 0; --j) { long long candidate = j; for (int i = 0; i < k; ++i) { while(candidate % p[i] == 0) { candidate /= p[i]; } } const bool found = candidate==1; if(found) { cout << j << endl; return 0; } } cout << "NIE" << endl; return 0; } |