#P5539. 【XR-3】Unknown Mother-Goose

【XR-3】Unknown Mother-Goose

Problem Description

Xiao X is given a positive integer nn and a set of positive integers SS. He wants to know how many positive integers xx satisfy all of the following conditions:

  • 3≤x≤n3 \le x \le n
  • There exists a∈Sa \in S such that x≡0(moda)x \equiv 0 \pmod a
  • There exists b∈Sb \in S such that x−1≡0(modb)x-1 \equiv 0 \pmod b
  • There exists c∈Sc \in S such that x−2≡0(modc)x-2 \equiv 0 \pmod c

Please help Xiao X compute the answer.

Input Format

The first line contains two positive integers n,∣S∣n, |S|, representing the given nn and the size of the set SS.

The second line contains ∣S∣|S| positive integers, representing the elements in the set SS.

Constraints:

  • 3≤n≤1093 \le n \le 10^9.
  • 3≤∣S∣≤203 \le |S| \le 20.
  • All elements in SS are less than nn. Elements are not guaranteed to be distinct.

Output Format

Output one integer in a single line, representing the answer.

10 3
2 4 5

1

100000 6
14 47 31 233 666 59

91

Hint

[Sample 11 Explanation]

Only when x=6x = 6:

  • x≡0(mod2)x \equiv 0 \pmod 2
  • x≡1(mod5)x \equiv 1 \pmod 5
  • x≡2(mod4)x \equiv 2 \pmod 4

do the conditions hold.

Translated by ChatGPT 5