#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <queue> //CF209 Div2 (D) 找最长的连续子序列拥有相同的最大公约数,并且最大公约数是这个序列中的一个数-------左右延伸的方法
#define N 300010
using namespace std;
int a[N], b[N];
int main()
{
int n, t, k, ans, l, r, h;
while(scanf("%d", &n)!=EOF)
{
for(t=1; t<=n; ++t)
scanf("%d", a+t);
ans=0;
for(t=1; t<=n; ) //左右延伸
{
l=r=t;
while(l>=1&&a[l]%a[t]==0)
l--;
while(r<=n&&a[r]%a[t]==0)
r++; //以上操作是将序号为t左右延伸到最大长度
h=r-l-1; //之前的最大长度
if(h>ans)
{
ans=h;
k=0;
}
if(h==ans)
{
b[k++]=l+1;
}
t=r; //t=r是下一个左右延伸的起点
}
printf("%d %d\n", k, ans-1);
for(t=0; t<k; ++t)
printf("%d ", b[t]);
printf("\n");
}
return 0;
}
CF209 Div2 (D) 找最长的连续子序列拥有相同的最大公约数,并且最大公约数是这个序列中的一个数-------左右延伸的方法
最新推荐文章于 2023-04-17 20:26:43 发布