This page is still under construction.

Parts of this page are still being built. What you see may change.

Arin and the Slot Machine

Time limit1sMemory limit1024 MB

Summary
Each operation picks a window of length M and a prime p other than 7, dividing every element in the window divisible by p by p; find the minimum number of operations to turn all values into 7, or -1.
Level

Medium7 of 10

Topics
Number theory, Greedy, Math, Implementation
Solved
No attempts yet

Problem

Arin went on vacation to Kangwon Land (Arin follows the government's disease prevention guidelines). The most popular game at Kangwon Land is the slot machine. While watching the slot machine, Arin could not help but be astonished, because she learned that a jackpot pays out a huge prize. Arin resolved to hit the jackpot, buy a house, buy a car, and eat lots of good food.

Arin has a slot machine with N cells. Each time the lever is pulled, each cell displays an arbitrary positive integer. If all cells display 7, the jackpot has been hit, and a huge prize is paid out.

However, operating the slot machine requires money. Arin, famous for being frugal, does not waste money on something like a slot machine. Instead of operating the slot machine, Arin can perform the following operation infinitely many times on the cells of the slot machine. Choose an interval [i, i + M) and a prime p other than 7. Then divide every number in the interval that is divisible by p by p. That is, among Si, Si+1, ..., Si+M-1, divide every number divisible by p by p. (1 ≤ i ≤ N - M + 1, p ≠ 7)

Given the state of the slot machine, write a program that finds the minimum number of operations needed to hit the jackpot, that is, to turn every number into 7.

Input

The first line gives the number of cells N of the slot machine and the interval length M.

The second line gives the N integers S1, S2, ..., SN displayed in the cells of the slot machine.

All input is separated by spaces.

Output

On the first line, print the minimum number of operations needed to hit the jackpot. If it is impossible to turn every number into 7, print -1.

Constraints

  • 1 ≤ N ≤ 50,000
  • 1 ≤ M ≤ N
  • 1 ≤ Si ≤ 10,000,000

Hint

The input is large, so using fast input is recommended.

Examples2

  1. Example 1

    Input
    5 3
    14 21 70 105 35
    
    Expected output
    3
    
  2. Example 2

    Input
    7 3
    7 8 9 10 11 12 13
    
    Expected output
    -1