Product
시간 제한2초메모리 제한8 MB
100 이하의 서로 다른 소수 k개와 10^18 이하의 N이 주어질 때, 소인수가 모두 그 집합에 속하면서 N을 넘지 않는 가장 큰 수를 찾는다.
문제
Warning: Pay attention to the unusual memory limit.
You are given prime numbers and an integer . Your task is to find the largest integer not exceeding whose prime factorization contains only these prime numbers.
For example, if the prime numbers are , the set of numbers whose factorization contains only these primes is .
입력
The first line of the input contains two integers (, ) described above. The second line contains distinct prime numbers ().
출력
You should output a single positive integer -- the largest number not exceeding whose prime factorization contains only prime numbers .