#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:

  • 3xn3 \le x \le n
  • There exists aSa \in S such that x0(moda)x \equiv 0 \pmod a
  • There exists bSb \in S such that x10(modb)x-1 \equiv 0 \pmod b
  • There exists cSc \in S such that x20(modc)x-2 \equiv 0 \pmod c

Please help Xiao X compute the answer.

Input Format

The first line contains two positive integers n,Sn, |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:

  • 3n1093 \le n \le 10^9.
  • 3S203 \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:

  • x0(mod2)x \equiv 0 \pmod 2
  • x1(mod5)x \equiv 1 \pmod 5
  • x2(mod4)x \equiv 2 \pmod 4

do the conditions hold.

Translated by ChatGPT 5