#include<iostream> #include<algorithm> #include<vector> using namespace std; vector<long long> v; bool check(long long x) { if(x==1) return true; for(const auto& d : v) { if(x%d==0) { if(check(x/d)) return true; } } return false; } int main() { ios_base::sync_with_stdio(false); long long x,k,N; cin >>k>>N; for(int i=0;i<k;i++) { cin >>x; v.push_back(x); } while(N) { if(check(N)) { cout <<N<<endl; break; } N--; } }
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 | #include<iostream> #include<algorithm> #include<vector> using namespace std; vector<long long> v; bool check(long long x) { if(x==1) return true; for(const auto& d : v) { if(x%d==0) { if(check(x/d)) return true; } } return false; } int main() { ios_base::sync_with_stdio(false); long long x,k,N; cin >>k>>N; for(int i=0;i<k;i++) { cin >>x; v.push_back(x); } while(N) { if(check(N)) { cout <<N<<endl; break; } N--; } } |