PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000221. Đếm số chia hết cho ít nhất một số nguyên tố (Prime Multiples)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm số chia hết cho ít nhất một số nguyên tố (Prime Multiples)

Prime Multiples

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Given a positive integer nn and kk distinct primes p1,…,pkp_1,\ldots,p_k, count integers xx in [1,n][1,n] divisible by at least one of these primes. Count each qualifying integer once.

Input

First line: n,kn,k. Second line: kk pairwise distinct primes pip_i.

Output

Print the count.

Subtasks

  • Subtask 1 (20 points): $1\le n\le 1000000,\ 1\le k\le 8,\ 2\le p_i\le n,\ p_i\text{ distinct primes}$.

  • Subtask 2 (30 points): $1\le n\le 1000000000000,\ 1\le k\le 15,\ 2\le p_i\le n,\ p_i\text{ distinct primes}$.

  • Subtask 3 (50 points): $1\le n\le 1000000000000000000,\ 1\le k\le 20,\ 2\le p_i\le n,\ p_i\text{ distinct primes}$.

Examples

Example 1

Input

20 2
2 5

Output

12

Explanation

The eligible numbers are 2,4,5,6,8,10,12,14,15,16,18,20, so the answer is 12.

Example 2

Input

10 1
3

Output

3

Explanation

The multiples of 3 in the interval are 3,6,9.