Fişierul intrare/ieşire:sieve2.in, sieve2.outSursăIIOT 2021-22 Runda 3
AutorGiorgio AudritoAdăugată destefdascalescuStefan Dascalescu stefdascalescu
Timp execuţie pe test1 secLimită de memorie131072 kbytes
Scorul tăuN/ADificultateN/A

Vezi solutiile trimise | Statistici

Sieve2

Giorgio is playing with the Sieve of Eratosthenes, one of the most ancient algorithms of all times. This algorithm starts with a row of all numbers from 2 to M, then repeatedly selects the smallest non-selected number remaining in the row, erasing every multiple of it. At the end of the process, only prime numbers will have survived in the row!

Giorgio is trying to apply a similar idea, but with few differences. Firstly, some numbers are missing from the starting row, which contains only N numbers overall (each of them between 2 and M), in increasing order. Secondly, every time Giorgio selects a number, he erases not only the multiples of it but also its divisors. As in the original algorithm, Giorgio keeps selecting numbers from the row (end erasing accordingly), stopping when every remaining number has been already selected; but he doesn't have to select numbers in increasing order. How many numbers can remain at the end of the process, at minimum?

Date de intrare

The first line of the input file sieve2.in contains N and M. The second line of the input contains the N integers in increasing order.

Date de ieşire

The output file sieve2.out will contain a single line with an integer: the minimum amount of numbers that must remain at the end of the process.

Restricţii

  • 1 ≤ N ≤ 250
  • 1 ≤ M ≤ 10^6
  • For tests worth 35 points, 1 ≤ N ≤ 9
  • For tests worth 15 more points, 1 ≤ M ≤ 20
  • For tests worth 20 more points, 1 ≤ N ≤ 50

Exemplu

sieve2.insieve2.out
6 10
3 4 6 7 8 9
3
sieve2.insieve2.out
6 20
2 5 7 10 14 20
2

Explicaţie

In the first sample case, one of the best strategies is to choose numbers 7, 3 and 4. Suboptimal solutions exist, such as choosing numbers 9, 8, 7 and 6.

In the second sample case, one of the best strategies is to choose numbers 20 and 14.

Trebuie sa te autentifici pentru a trimite solutii. Click aici

Cum se trimit solutii?