Simon has an array a1, a2, ..., an, 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 al, al + 1, ..., ar are divisible by aj;
  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.

Input

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

The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 106).

Output

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.

Example

Input
  1. 5
    4 6 9 3 6
Output
  1. 1 3
    2
Input
  1. 5
    1 3 5 7 9
Output
  1. 1 4
    1
Input
  1. 5
    2 3 5 7 11
Output
  1. 5 0
    1 2 3 4 5

Note

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).

要找个最长区间,使得区间里存在一个数x,区间其他数都能被它整除

对于一个i,直接暴力O(n)找左右两边能被a[i]整除的最远的l,r

同时,如果找到了一个i的[l,r],那么对于所有i<j<=r,a[i] | a[j],所以a[j]的对应[l,r]不会比i的更优

所以做完 i 之后可以直接 i 跳到 r+1 的位置

这样还挺快啊?

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<cstdlib>
  5. #include<algorithm>
  6. #include<cmath>
  7. #include<queue>
  8. #include<deque>
  9. #include<set>
  10. #include<map>
  11. #include<ctime>
  12. #define LL long long
  13. #define inf 0x7ffffff
  14. #define pa pair<int,int>
  15. #define mkp(a,b) make_pair(a,b)
  16. #define pi 3.1415926535897932384626433832795028841971
  17. using namespace std;
  18. inline LL read()
  19. {
  20. LL x=,f=;char ch=getchar();
  21. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  22. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  23. return x*f;
  24. }
  25. int n;
  26. int a[];
  27. int len,tot;
  28. int ans[];
  29. int main()
  30. {
  31. n=read();
  32. for (int i=;i<=n;i++)a[i]=read();
  33. for (int i=;i<=n;i++)
  34. {
  35. int l=i,r=i;
  36. while (l>=&&a[l]%a[i]==)l--;l++;
  37. while (r<=n&&a[r]%a[i]==)r++;r--;
  38. if (r-l>len){len=r-l;tot=;ans[tot]=l;}
  39. else if (r-l==len)ans[++tot]=l;
  40. i=r;
  41. }
  42. printf("%d %d\n",tot,len);
  43. for(int i=;i<=tot;i++)printf("%d ",ans[i]);
  44. }

cf359D

cf359D Pair of Numbers的更多相关文章

  1. CF359D Pair of Numbers gcd+暴力

    利用区间 gcd 个数不超过 log 种来做就可以了~ code: #include <bits/stdc++.h> #define N 300005 #define setIO(s) f ...

  2. Codeforces 395 D.Pair of Numbers

    D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces Round #209 (Div. 2) D. Pair of Numbers (模拟)

    D. Pair of Numbers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  4. CF359D:Pair of Numbers——题解

    https://vjudge.net/problem/CodeForces-359D http://codeforces.com/problemset/problem/359/D 题目大意: 给一串数 ...

  5. CodeForces 359D Pair of Numbers (暴力)

    题意:给定一个正整数数组,求最长的区间,使得该区间内存在一个元素,它能整除该区间的每个元素. 析:暴力每一个可能的区间,从数组的第一个元素开始考虑,向两边延伸,设延伸到的最左边的点为l, 最右边的点为 ...

  6. Pair of Numbers

    Codeforces Round #209 (Div. 2) D:http://codeforces.com/contest/359/problem/D 题意:给以一个n个数的序列,然后问你最大的区间 ...

  7. cf D. Pair of Numbers

    http://codeforces.com/contest/359/problem/D 题意:给你n个数,然后找出在[l,r]中有一个数a[j],l<=j<=r,在[l,r]中的所有数都是 ...

  8. [codeforces] 359D Pair of Numbers

    原题 RMQ st表棵题 要想让一个区间里的所有数都可以整除其中一个数,那么他一定是这个区间内的最小值,并且同时是这个区间的gcd.然后这个问题就转化成了RMQ问题. 维护两个st表,分别是最小值和g ...

  9. Codeforces 359D Pair of Numbers | 二分+ST表+gcd

    题面: 给一个序列,求最长的合法区间,合法被定义为这个序列的gcd=区间最小值 输出最长合法区间个数,r-l长度 接下来输出每个合法区间的左端点 题解: 由于区间gcd满足单调性,所以我们可以二分区间 ...

随机推荐

  1. jQuery JavaScript Library v3.2.1

    /*! * jQuery JavaScript Library v3.2.1 * https://jquery.com/ * * Includes Sizzle.js * https://sizzle ...

  2. 2019.05.26 周日--《阿里巴巴 Java 开发手册》精华摘要

    一.写在开头 Java作为一个编程界最流行的语言之一,有着很强的生命力.代码的编写规范也是不容忽视的,今天,我就把自己阅读的国内的互联网巨头阿里巴巴的<阿里巴巴 Java 开发手册>一些精 ...

  3. VueJS坎坷之路222--vue cli 3.0引入静态文件

    前两天准备搭建一个vue小项目,当引入jquery脚本的时候一直找不到引入的文件: 在网上搜了好多vue添加静态文件的方法,发现大多数方法都是创建一个与文件夹src同等级的文件夹static存放引入的 ...

  4. 【Mysql】Mysql主从库搭建过程(爬完坑后整理所得)

    Mysql主从数据库搭建流程 新手开始学习mysql主从库,遇到一些问题,总结后写出以下流程 下面以5.7.23版本为例介绍 第一步:去官网下载5.7.23版本的免安装压缩包形式的mysql文件,贴上 ...

  5. DC 课程内容

  6. 补之前 如何改变jupyter打开文件的路径

    目录 如何改变jupyter打开文件的路径 第一种方法: 第二种方法 第三种方法 如何改变jupyter打开文件的路径 当我们直接打开jupyter时,直接加载的是我们的C盘文件 现在我们想打开其他盘 ...

  7. 使用TensorFlow的卷积神经网络识别手写数字(3)-识别篇

    from PIL import Image import numpy as np import tensorflow as tf import time bShowAccuracy = True # ...

  8. POJ:2411-Mondriaan's Dream(矩形拼接方案)

    题目链接:http://poj.org/problem?id=2411 解题心得: 可以说是很经典的一个状压dp了,写dfs遍历肯定是要超时的,这个题的状态转移方程对新手来说有点吃力. 状态转移用的是 ...

  9. Leetcode 559. N叉树的最大深度

    题目链接 https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree/description/ 题目描述 给定一个N叉树,找到其最大深度. ...

  10. redis--py链接redis【转】

    请给原作者点赞--> 原文链接 一.redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链 ...