#include <bits/stdc++.h>
using namespace std;
vector<long long> p;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
long long k, n;
cin >> k >> n;
int x;
for(int i = 0; i < k; i++)
{
cin >> x;
p.push_back(x);
}
sort(p.begin(), p.end());
long long z;
int g;
for(; n > 1; n--)
{
g = 0;
z=n;
while(g < p.size() && z > 0)
{
if(z%p[g]==0)
z/=p[g];
else
g++;
}
if(z==1)
break;
}
cout << n;
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 | #include <bits/stdc++.h> using namespace std; vector<long long> p; int main() { ios::sync_with_stdio(0); cin.tie(0); long long k, n; cin >> k >> n; int x; for(int i = 0; i < k; i++) { cin >> x; p.push_back(x); } sort(p.begin(), p.end()); long long z; int g; for(; n > 1; n--) { g = 0; z=n; while(g < p.size() && z > 0) { if(z%p[g]==0) z/=p[g]; else g++; } if(z==1) break; } cout << n; return 0; } |
English