CF359D.Pair of Numbers

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Simon has an array _a_1, _a_2, ..., a__n, consisting of n positive integers. Today Simon asked you to find a pair of integers l, r (1 ≤ l ≤ r ≤ n), such that the following conditions hold:

  1. there is integer j (l ≤ j ≤ r), such that all integers a__l, a__l + 1, ..., a__r are divisible by a__j;
  2. value r - l takes the maximum value among all pairs for which condition 1 is true;

Help Simon, find the required pair of numbers (l, r). If there are multiple required pairs find all of them.

西蒙有一个由 nn 个正整数组成的数组 a1,a2,…,ana_1, a_2, \dots, a_n。今天西蒙请你找出一对整数 l,rl, r(满足 1≤l≤r≤n1 \leq l \leq r \leq n),使得以下条件成立:

  1. 存在某个整数 jj(满足 l≤j≤rl \leq j \leq r),使得子数组 al,al+1,…,ara_l, a_{l+1}, \dots, a_r 中的所有整数均能被 aja_j 整除;
  2. 在所有满足条件 1 的数对中,r−lr - l 的值达到最大。

请帮助西蒙找出满足要求的数对 (l,r)(l, r)。如果存在多个满足要求的数对,请全部找出。

输入格式

The first line contains integer n (1 ≤ n ≤ 3·105).

The second line contains n space-separated integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 106).

第一行包含一个整数 nn(1≤n≤3⋅1051 \leq n \leq 3 \cdot 10^5)。

第二行包含 nn 个以空格分隔的整数 a1, a2, …, ana_1,\ a_2,\ \dots,\ a_n(1≤ai≤1061 \leq a_i \leq 10^6)。

输出格式

Print two integers in the first line — the number of required pairs and the maximum value of r - l. On the following line print all l values from optimal pairs in increasing order.

第一行输出两个整数——所需数对的个数,以及 r−lr - l 的最大值。
下一行按升序输出所有最优数对的 ll 值。

输入输出样例

  • 输入#1

    5
    4 6 9 3 6

    输出#1

    1 3
    2
  • 输入#2

    5
    1 3 5 7 9

    输出#2

    1 4
    1
  • 输入#3

    5
    2 3 5 7 11

    输出#3

    5 0
    1 2 3 4 5

说明/提示

In the first sample the pair of numbers is right, as numbers 6, 9, 3 are divisible by 3.

In the second sample all numbers are divisible by number 1.

In the third sample all numbers are prime, so conditions 1 and 2 are true only for pairs of numbers (1, 1), (2, 2), (3, 3), (4, 4), (5, 5).

在第一个样例中,数对是正确的,因为数字 6、9、3 均能被 3 整除。

在第二个样例中,所有数字均能被数字 1 整除。

在第三个样例中,所有数字均为质数,因此条件 1 和条件 2 仅对数对 (1, 1)、(2, 2)、(3, 3)、(4, 4)、(5, 5) 成立。

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

首页