#P4411. [BJWC2010] 取数游戏

[BJWC2010] 取数游戏

Description

Xiao C has just learned the Euclidean algorithm and is enjoying it, but Xiao P comes to make trouble and leaves Xiao C with a hard problem. You are given NN numbers, denoted by a1,a2,,ana_1, a_2, \cdots, a_n. Now Xiao P asks Xiao C to pick numbers one by one in order. The first number can be chosen arbitrarily. Suppose the current number is aja_j. To pick the next number aka_k with k>jk > j, the number aka_k must satisfy gcd(aj,ak)L\mathrm{gcd}(a_j, a_k) \ge L.

How many numbers should be picked? Naturally, as many as possible. Needless to say, this is not only a challenge for Xiao C, but also for you.

Input Format

The first line contains two numbers NN and LL.
The second line contains NN numbers separated by spaces: a1,a2,,ana_1, a_2, \cdots, a_n.

Output Format

Output a single line with one number, the maximum count of numbers that can be picked according to the rule.

5 6 
7 16 9 24 6
3

Hint

Sample Explanation

Pick 33 numbers: 16,24,616, 24, 6. gcd(16,24)=8\mathrm{gcd}(16, 24) = 8, gcd(6,24)=6\mathrm{gcd}(6, 24) = 6.

Constraints

For 30% of the testdata, N1000N \le 1000.
For 100% of the testdata, N50000N \le 50\,000, 2Lai10000002 \le L \le a_i \le 1\,000\,000.

Translated by ChatGPT 5