#P5539. Counting Valid Integers
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:
- \( 3 \le x \le n \)
- There exists an element \( a \in S \) such that \( x \equiv 0 \pmod{a} \).
- There exists an element \( b \in S \) such that \( x-1 \equiv 0 \pmod{b} \).
- 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