P22406 [HackerRank] Easy gcd 1
普及
题目描述

We call a sequence of $n$ non-negative integers, ${A}$, awesome if there exists some positive integer $x>1$ such that each element $a_i$ in ${A}$ (where $0\leq i<n$) is evenly divisible by ${x}$. Recall that ${a}$ evenly divides ${b}$ if there exists some integer ${c}$ such that $b=a\cdot c$.

Given an awesome sequence, ${A}$, and a positive integer, ${k}$, find and print the maximum integer, ${l}$, satisfying the following conditions:

$0\leq l\leq k$
$A\cup\{l\}$ is also awesome.

Input Format

The first line contains two space-separated positive integers, $n$ (the length of sequence ${A}$) and ${k}$ (the upper bound on answer ${l}$), respectively.

The second line contains $n$ space-separated positive integers describing the respective elements in sequence ${A}$ (i.e., $a_0,a_1,\ldots,a_{n-1}$).

Constraints

$1\leq n\leq10^5$
$1\leq k\leq10^9$
$1\leq a_i\leq10^9$

Output Format

Print a single, non-negative integer denoting the value of ${l}$ (i.e., the maximum integer $\leq k$ such that $A\cup\{l\}$ is awesome). As ${0}$ is evenly divisible by any $x>1$, the answer will always exist.

Sample Input 0

3 5
2 6 4

Sample Output 0

4

Explanation 0

The only common positive divisor of $2$, ${6}$, and ${4}$ that is ${>1}$ is $2$, and we need to find ${l}$ such that $0\leq l\leq5$. We know $l\neq5$ because $x=2$ would not evenly divide $5$. When we look at the next possible value, $l=4$, we find that this is valid because it's evenly divisible by our ${x}$ value. Thus, we print ${4}$.

Sample Input 1

1 5
7

Sample Output 1

0

Explanation 1

Being prime, $7$ is the only possible value of $x>1$. The only possible ${l}$ such that $0\leq l\leq5$ is ${0}$ (recall that $\frac{0}{7}=0$), so we print ${0}$ as our answer.

输入格式

见题面

输出格式

见题面

样例输入
3 5 2 6 4
样例输出
4