#include <iostream> #include <algorithm> using namespace std; typedef long long ull; int main() { cin.sync_with_stdio(false); cin.tie(nullptr); int k; ull n; cin>>k>>n; short primes[k]; for (short i = 0; i < k; i++) { cin>>primes[i]; } sort(primes, primes+k); ull temp = n, max; for (ull i = n; i > 0; i--) { max = 1; temp = i; for (int j = k-1; j >= 0; j--) { while (temp % primes[j] == 0) { temp /= primes[j]; max *= primes[j]; } if (temp == 1) { cout<<max; exit(0); } } } cout<<max; 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 <algorithm> using namespace std; typedef long long ull; int main() { cin.sync_with_stdio(false); cin.tie(nullptr); int k; ull n; cin>>k>>n; short primes[k]; for (short i = 0; i < k; i++) { cin>>primes[i]; } sort(primes, primes+k); ull temp = n, max; for (ull i = n; i > 0; i--) { max = 1; temp = i; for (int j = k-1; j >= 0; j--) { while (temp % primes[j] == 0) { temp /= primes[j]; max *= primes[j]; } if (temp == 1) { cout<<max; exit(0); } } } cout<<max; return 0; } |