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

#SP0000225. Phân tích thị trường phức tạp (Complex Market Analysis)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Phân tích thị trường phức tạp (Complex Market Analysis)

Complex Market Analysis

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

William has an array aa of nn positive integers and a jump size ee. Consider pairs of positive integers (i,k)(i,k) satisfying i+ke≤ni+ke\le n.

For a pair, take the array elements at positions i,i+e,i+2e,…,i+kei,i+e,i+2e,\ldots,i+ke. Because k≥1k\ge1, this sequence contains at least two elements.

Count the pairs for which the product of all selected values is prime. Array indices start at 11.

Input

The first line contains integers nn and ee. The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print the number of valid pairs (i,k)(i,k) with prime product and k≥1k\ge1.

Subtasks

  • Subtask 1 (20 points): 1≤e≤n≤201\le e\le n\le20; 1≤ai≤1061\le a_i\le10^6 for every ii.

  • Subtask 2 (30 points): 1≤e≤n≤20001\le e\le n\le2000; 1≤ai≤1061\le a_i\le10^6 for every ii.

  • Subtask 3 (50 points): 1≤e≤n≤2⋅1051\le e\le n\le2\cdot10^5; 1≤ai≤1061\le a_i\le10^6 for every ii.

Examples

Input

7 3
10 2 1 3 1 19 3

Output

2

Explanation

For n=7n=7 and e=3e=3, pair (2,1)(2,1) uses a2=2a_2=2 and a5=1a_5=1, with prime product 22. Pair (3,1)(3,1) uses a3=1a_3=1 and a6=19a_6=19, with prime product 1919. All other candidate pairs contain a composite factor, at least two factors greater than 11, or have product 11. Therefore the answer is 2.