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
42
43
44
45
46
47
// Iloczyn.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>


int main()
{
	unsigned int k;
	long long N;
	std::cin >> k >> N;

	std::vector<int> primes(k);

	for (auto i = 0u; i < k; ++i)
	{
		std::cin >> primes[i];
	}
	std::sort(primes.begin(), primes.end());

	std::set<long long> results(primes.begin(), primes.end());

	while (N/primes[0] >= *results.begin())
	{
		auto elem = *results.begin();
		for (auto &prime : primes)
		{
			if (N / prime >= elem)
			{
				results.insert(elem*prime);
			}
			else
			{
				break;
			}
		}
		results.erase(results.begin());
	}

	auto result = --results.upper_bound(N);
	std::cout << *result << std::endl;

    return 0;
}