CF1730E.Maximums and Minimums

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given an array a1,a2,,ana_1, a_2, \ldots, a_n of positive integers.

Find the number of pairs of indices (l,r)(l, r) , where 1lrn1 \le l \le r \le n , that pass the check. The check is performed in the following manner:

  1. The minimum and maximum numbers are found among al,al+1,,ara_l, a_{l+1}, \ldots, a_r .
  2. The check is passed if the maximum number is divisible by the minimum number.

输入格式

The first line contains a single integer tt ( 1t101 \le t \le 10 ) — the number of test cases. Then the test cases follow.

Each test case consists of two lines.

The first line contains a single integer nn ( 1n51051 \le n \le 5 \cdot 10^5 ) — the size of the array.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ai1061 \le a_i \le 10^6 ).

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

输出格式

For each test case, print a single integer — the number of pairs of indices that pass the check.

输入输出样例

  • 输入#1

    6
    1
    1
    2
    2 4
    2
    2 3
    4
    2 4 7 14
    7
    16 5 18 7 7 12 14
    6
    16 14 2 6 16 2

    输出#1

    1
    3
    2
    7
    10
    19

说明/提示

Below xyx \mid y denotes that yy is divisible by xx .

In the first test case, there is one pair (1,1)(1, 1) , the maximum for this pair is 11 , the minimum is also 11 , 111 \mid 1 , so the check is passed, and the answer is 11 .

In the second test case, there are 33 segments:

  • (1,1)(1, 1) : the maximum is 22 , the minimum is 22 , 222 \mid 2 , so the check is passed.
  • (1,2)(1, 2) : the maximum is 44 , the minimum is 22 , 242 \mid 4 , so the check is passed.
  • (2,2)(2, 2) : the maximum is 44 , the minimum is 44 , 444 \mid 4 , so the check is passed.

In the third test case, there are 33 segments:

  • (1,1)(1, 1) : the maximum is 22 , the minimum is 22 , 222 \mid 2 , so the check is passed.
  • (1,2)(1, 2) : the maximum is 33 , the minimum is 22 , 33 isn't divisible by 22 , so the check is failed.
  • (2,2)(2, 2) : the maximum is 33 , the minimum is 33 , 333 \mid 3 , so the check is passed.
首页