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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;

std::vector<long> PrimeFactorization1(long long n);
int IsCorrectNumber(long long n, vector<long>& pirmaries, int k);

int main()
{
	long long k;
	long long N;

	std::cin >> k;
	std::cin >> N;
	std::vector<long> pirmaries(k);

	for (int i = 0; i < k; i++){
		std::cin >> pirmaries[i];
	}

	long long max = 1;
	for (long long i = 1; i <= N; i++) {
		if (IsCorrectNumber(i, pirmaries, k) == 0)
		{
			max = i;
		}
	}

	std::cout << max;

	return 0;
}

int IsCorrectNumber(long long n, vector<long>& pirmaries, int k) {
	long ws[] = {1, 2, 2, 4, 2, 4, 2, 4, 6, 2, 6};
	long f = 2; int w = 0;

	while (f * f <= n) {
		if (n % f == 0) {
			if (f < pirmaries[0] || f > pirmaries[k]) {
				return -1;
			} else {
				int found = 0;
				for (int i = 0; i < k; i++)
				{
					if (f == pirmaries[i]) {
						found = 1;
						break;
					}
				}

				if (found == 0) {
					return -1;
				}
			}

			n /= f;
		} else {
			f += ws[w];
			w = (w == 10) ? 3 : (w +1);
		}
	}
	
	if (n < pirmaries[0] || n > pirmaries[k]) {
		return -1;
	} else {
		int found = 0;
		for (int i = 0; i < k; i++)
		{
			if (n == pirmaries[i]) {
				found = 1;
				break;
			}
		}

		if (found == 0) {
			return -1;
		}
	}

	return 0;
}