#P5539. Counting Valid Integers

    ID: 18769 Type: Default 1000ms 256MiB

Counting Valid Integers

Counting Valid Integers

Given a positive integer \( n \) and a set \( S \) of positive integers, determine how many positive integers \( x \) satisfy all of the following conditions:

  1. \( 3 \le x \le n \)
  2. There exists an element \( a \in S \) such that \( x \equiv 0 \pmod{a} \).
  3. There exists an element \( b \in S \) such that \( x-1 \equiv 0 \pmod{b} \).
  4. There exists an element \( c \in S \) such that \( x-2 \equiv 0 \pmod{c} \).

Your task is to compute the number of such integers \( x \).

inputFormat

The input consists of two lines:

  • The first line contains two positive integers \( n \) and \( k \), where \( n \) is the upper bound for \( x \) and \( k \) is the number of elements in the set \( S \).
  • The second line contains \( k \) positive integers representing the elements of \( S \), separated by spaces.

outputFormat

Output a single integer: the count of valid integers \( x \) that satisfy all the conditions.

sample

10 2
2 3
2