#include <iostream> #include <vector> using namespace std; int main() { vector <long long int> potegi; long long int k; long long int n; cin >> k; cin >> n; for(int i = 0; i < k; i++) { int l; cin >> l; potegi.push_back(l); } for(long long int j = n; j > 0; j--) { long long int temp = j; for(long long int i = 0; i < potegi.size(); i++) { while(temp % potegi[i] == 0) { temp = temp / potegi[i]; } } if(temp == 1) { cout << j << endl; return 0; } } cout << "1" << 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 31 32 33 34 35 36 37 38 | #include <iostream> #include <vector> using namespace std; int main() { vector <long long int> potegi; long long int k; long long int n; cin >> k; cin >> n; for(int i = 0; i < k; i++) { int l; cin >> l; potegi.push_back(l); } for(long long int j = n; j > 0; j--) { long long int temp = j; for(long long int i = 0; i < potegi.size(); i++) { while(temp % potegi[i] == 0) { temp = temp / potegi[i]; } } if(temp == 1) { cout << j << endl; return 0; } } cout << "1" << endl; return 0; } |