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
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

vector < int > p;

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

    scanf( "%d%lld", &k, &N );
    while ( k-- )
    {
        scanf( "%d", &x );
        p.push_back( x );
    }

    if ( p.size() == 1 )
    {
        long long result = 1;
        while ( result <= N / p[ 0 ] ) result *= p [ 0 ];
        printf( "%lld", result );
    }
    else
    {
        long long n;
        for ( N; ; N-- )
        {
            n = N;

            for ( int i = 0; i < p.size(); ++i )
            {
                while ( n % p [ i ] == 0 ) n /= p[ i ];
            }
            if ( n == 1 ) break;
        }
        printf( "%lld", N );
    }

}