OO’s Sequence

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5288

Description

OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l<=i<=r) , that there's no j(l<=j<=r,j<>i) satisfy ai mod aj=0,now OO want to know

∑i=1n∑j=inf(i,j) mod (109+7).

Input

There are multiple test cases. Please process till EOF.

In each test case:

First line: an integer n(n<=10^5) indicating the size of array

Second line:contain n numbers ai(0<ai<=10000)

Output

For each tests: ouput a line contain a number ans.

Sample Input

5

1 2 3 4 5

Sample Output

23

Hint

题意

f(l,r)表示[l,r]区间中有多少个i满足在这个区间中找不到其他j使得ai%aj=0

然后让你输出所有f(l,r)的累加。

题解:

对于每一个位置,我算贡献就好了。

直接暴力分解a[i]就好了。

复杂度nsqrtn的。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+6;
const int mod = 1e9+7;
int a[maxn],n;
int L[maxn],R[maxn];
int p[maxn];
int main()
{
while(scanf("%d",&n)!=EOF)
{
memset(L,0,sizeof(L));
memset(R,0,sizeof(R));
memset(p,0,sizeof(p));
memset(a,0,sizeof(a));
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=sqrt(a[i]);j++)
if(a[i]%j==0)L[i]=max(L[i],p[j]+1),L[i]=max(L[i],p[a[i]/j]+1);
p[a[i]]=i;
}
reverse(a+1,a+1+n);
memset(p,0,sizeof(p));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=sqrt(a[i]);j++)
if(a[i]%j==0)R[i]=max(R[i],p[j]+1),R[i]=max(R[i],p[a[i]/j]+1);
p[a[i]]=i;
}
long long ans = 0;
for(int i=1;i<=n;i++)
{
ans += 1ll*(i-L[i]+1)*(n-R[n-i+1]+1-i+1);
ans%=mod;
//cout<<L[i]<<" "<<n-R[i]+1<<endl;
}
cout<<ans<<endl;
}
}

HDU 5288 OO’s Sequence 水题的更多相关文章

  1. HDU 5288 OO’s Sequence [数学]

     HDU 5288 OO’s Sequence http://acm.hdu.edu.cn/showproblem.php?pid=5288 OO has got a array A of size ...

  2. HDU 5288——OO’s Sequence——————【技巧题】

    OO’s Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  3. Hdu 5288 OO’s Sequence 2015多小联赛A题

    OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  4. HDU 5288 OO‘s sequence (技巧)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...

  5. HDOJ 5288 OO’s Sequence 水

    预处理出每一个数字的左右两边能够整除它的近期的数的位置 OO's Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 13 ...

  6. hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)

    OO's Sequence                                                          Time Limit: 4000/2000 MS (Jav ...

  7. hdu 5288 OO’s Sequence(2015多校第一场第1题)枚举因子

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5288 题意:在闭区间[l,r]内有一个数a[i],a[i]不能整除 除去自身以外的其他的数,f(l,r ...

  8. hdu 5288 OO’s Sequence 枚举+二分

    Problem Description OO has got a array A of size n ,defined a function f(l,r) represent the number o ...

  9. HDU 5288 OO’s Sequence

    题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...

随机推荐

  1. 【DeepLearning学习笔记】Coursera课程《Neural Networks and Deep Learning》——Week2 Neural Networks Basics课堂笔记

    Coursera课程<Neural Networks and Deep Learning> deeplearning.ai Week2 Neural Networks Basics 2.1 ...

  2. 阿里云ECS安装Docker

    阿里云ESC系统信息,官方说2.6内核运行docker服务可能会不稳定: $ uname -a Linux iZ259dixwg8Z -.el6.x86_64 # SMP Thu Jul :: UTC ...

  3. SAE如何使用Git

    了解Git及远程git仓库 请先看博文<Git入门及上传项目到github中>,弄懂了之后我相信我下面说的就相当于废话了. SAE的git远程仓库就相当于github. 向SAE的远程仓库 ...

  4. overflow属性在IE6下面失去效果

    自然状态下 overflow的属性设置,本来是超过了一定的长度时会自动产生滚动条,但是在ie6下面失效了. 例如:原来的代码: .code{overflow-x:auto;margin:5px aut ...

  5. 高德地图web 端智能围栏

    最近有个项目,需要在web上批量给设备设置智能围栏,设备超出范围报警,查看高德地图webJS API,web端操作案例如,后台判断没有提供源码 <!-- 重点参数:iconStyle --> ...

  6. http协议及http协议和tcp协议的区别

    http是应用层的协议,并且无连接,无状态的协议. http协议的特点: 1.支持c/s模式 2.简单快速:客户端向服务器端传送数据的时候,只需要发送请求方法和路径,请求方法有:post,get,he ...

  7. 机器学习方法:回归(二):稀疏与正则约束ridge regression,Lasso

    欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. "机器学习方法"系列,我本着开放与共享(open and share)的精神撰写,目的是 ...

  8. Matlab处理数据导出Paraview可读的vtk文件(一)

    Paraview是一个开源的可视化软件. 用到matlab子程序从这里下载 或者到博客末尾复制粘贴 子程序名为 vtkwrite 示例1: load mri D = squeeze(D); vtkwr ...

  9. 主机批量扫描工具fping,hping安装及使用

    https://blog.csdn.net/weixin_39762926/article/details/79476196?utm_source=blogxgwz0 https://blog.csd ...

  10. JS框架的实现

    众多流行的JS库都不同程度的污染了原生JS,最典型的如Prototype ,Mootools .JQuery则完全例外,一个匿名函数执行后便诞生了集所有API为一身的强大 $ .虽然如此,JQuery ...