CF1609C.Complex Market Analysis

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

While performing complex market analysis William encountered the following problem:

For a given array aa of size nn and a natural number ee, calculate the number of pairs of natural numbers (i,k)(i, k) which satisfy the following conditions:

  • 1≤i,k1 \le i, k
  • i+e⋅k≤ni + e \cdot k \le n.
  • Product $a_i \cdot a_{i + e} \cdot a_{i + 2 \cdot e} \cdot \ldots \cdot a_{i + k \cdot e} $ is a prime number.

A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers.

威廉在进行复杂的市场分析时遇到了如下问题:

给定一个长度为 nn 的数组 aa 和一个正整数 ee,请计算满足以下条件的正整数对 (i,k)(i, k) 的个数:

  • 1≤i,k1 \le i, k;
  • i+e⋅k≤ni + e \cdot k \le n;
  • 乘积 ai⋅ai+e⋅ai+2⋅e⋅…⋅ai+k⋅ea_i \cdot a_{i + e} \cdot a_{i + 2 \cdot e} \cdot \ldots \cdot a_{i + k \cdot e} 是一个质数。

质数(或素数)是指大于 1 的自然数,且不能表示为两个更小的自然数的乘积。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10 0001 \le t \le 10\,000). Description of the test cases follows.

The first line of each test case contains two integers nn and ee (1≤e≤n≤2⋅105)(1 \le e \le n \le 2 \cdot 10^5), the number of items in the array and number ee, respectively.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤106)(1 \le a_i \le 10^6), the contents of the array.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤10 0001 \le t \le 10\,000)。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 ee(1≤e≤n≤2⋅1051 \le e \le n \le 2 \cdot 10^5),分别表示数组中的元素个数和数字 ee。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1061 \le a_i \le 10^6),表示数组的内容。

保证所有测试用例的 nn 之和不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case output the answer in the following format:

Output one line containing the number of pairs of numbers (i,k)(i, k) which satisfy the conditions.

对于每个测试用例,按以下格式输出答案:

输出一行,包含满足条件的数对 (i,k)(i, k) 的个数。

输入输出样例

  • 输入#1

    6
    7 3
    10 2 1 3 1 19 3
    3 2
    1 13 1
    9 3
    2 4 2 1 1 1 1 4 2
    3 1
    1 1 1
    4 1
    1 2 1 1
    2 2
    1 2

    输出#1

    2
    0
    4
    0
    5
    0

说明/提示

In the first example test case two pairs satisfy the conditions:

  1. i=2,k=1i = 2, k = 1, for which the product is: a2⋅a5=2a_{2} \cdot a_{5} = 2 which is a prime number.
  2. i=3,k=1i = 3, k = 1, for which the product is: a3⋅a6=19a_{3} \cdot a_{6} = 19 which is a prime number.

In the second example test case there are no pairs that satisfy the conditions.

In the third example test case four pairs satisfy the conditions:

  1. i=1,k=1i = 1, k = 1, for which the product is: a1⋅a4=2a_{1} \cdot a_{4} = 2 which is a prime number.
  2. i=1,k=2i = 1, k = 2, for which the product is: a1⋅a4⋅a7=2a_{1} \cdot a_{4} \cdot a_{7} = 2 which is a prime number.
  3. i=3,k=1i = 3, k = 1, for which the product is: a3⋅a6=2a_{3} \cdot a_{6} = 2 which is a prime number.
  4. i=6,k=1i = 6, k = 1, for which the product is: a6⋅a9=2a_{6} \cdot a_{9} = 2 which is a prime number.

In the fourth example test case there are no pairs that satisfy the conditions.

In the fifth example test case five pairs satisfy the conditions:

  1. i=1,k=1i = 1, k = 1, for which the product is: a1⋅a2=2a_{1} \cdot a_{2} = 2 which is a prime number.
  2. i=1,k=2i = 1, k = 2, for which the product is: a1⋅a2⋅a3=2a_{1} \cdot a_{2} \cdot a_{3} = 2 which is a prime number.
  3. i=1,k=3i = 1, k = 3, for which the product is: a1⋅a2⋅a3⋅a4=2a_{1} \cdot a_{2} \cdot a_{3} \cdot a_{4} = 2 which is a prime number.
  4. i=2,k=1i = 2, k = 1, for which the product is: a2⋅a3=2a_{2} \cdot a_{3} = 2 which is a prime number.
  5. i=2,k=2i = 2, k = 2, for which the product is: a2⋅a3⋅a4=2a_{2} \cdot a_{3} \cdot a_{4} = 2 which is a prime number.

In the sixth example test case there are no pairs that satisfy the conditions.

在第一个样例测试用例中,有两对 (i,k)(i, k) 满足条件:

  1. i=2,k=1i = 2, k = 1,对应乘积为:a2⋅a5=2a_{2} \cdot a_{5} = 2,这是一个质数。
  2. i=3,k=1i = 3, k = 1,对应乘积为:a3⋅a6=19a_{3} \cdot a_{6} = 19,这是一个质数。

在第二个样例测试用例中,不存在满足条件的数对。

在第三个样例测试用例中,有四对 (i,k)(i, k) 满足条件:

  1. i=1,k=1i = 1, k = 1,对应乘积为:a1⋅a4=2a_{1} \cdot a_{4} = 2,这是一个质数。
  2. i=1,k=2i = 1, k = 2,对应乘积为:a1⋅a4⋅a7=2a_{1} \cdot a_{4} \cdot a_{7} = 2,这是一个质数。
  3. i=3,k=1i = 3, k = 1,对应乘积为:a3⋅a6=2a_{3} \cdot a_{6} = 2,这是一个质数。
  4. i=6,k=1i = 6, k = 1,对应乘积为:a6⋅a9=2a_{6} \cdot a_{9} = 2,这是一个质数。

在第四个样例测试用例中,不存在满足条件的数对。

在第五个样例测试用例中,有五对 (i,k)(i, k) 满足条件:

  1. i=1,k=1i = 1, k = 1,对应乘积为:a1⋅a2=2a_{1} \cdot a_{2} = 2,这是一个质数。
  2. i=1,k=2i = 1, k = 2,对应乘积为:a1⋅a2⋅a3=2a_{1} \cdot a_{2} \cdot a_{3} = 2,这是一个质数。
  3. i=1,k=3i = 1, k = 3,对应乘积为:a1⋅a2⋅a3⋅a4=2a_{1} \cdot a_{2} \cdot a_{3} \cdot a_{4} = 2,这是一个质数。
  4. i=2,k=1i = 2, k = 1,对应乘积为:a2⋅a3=2a_{2} \cdot a_{3} = 2,这是一个质数。
  5. i=2,k=2i = 2, k = 2,对应乘积为:a2⋅a3⋅a4=2a_{2} \cdot a_{3} \cdot a_{4} = 2,这是一个质数。

在第六个样例测试用例中,不存在满足条件的数对。

输入解题思路,AI测评打分。不知道怎么写?

首页