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. Caffe 学习笔记1

    Caffe 学习笔记1 本文为原创作品,未经本人同意,禁止转载,禁止用于商业用途!本人对博客使用拥有最终解释权 欢迎关注我的博客:http://blog.csdn.net/hit2015spring和 ...

  2. Vue组件-动态组件

    动态组件 通过使用保留的 <component> 元素,动态地绑定到它的 is 特性,可以让多个组件使用同一个挂载点,并动态切换: <div id="app6"& ...

  3. Git常规配置与基本用法

    Git环境配置 一. 全局配置 1. 配置文件 git全局配置文件.gitconfig默认在当前系统用户文件夹下,window可运行%USERPROFILE%查找,Mac系统在cd ~查找. 具体配置 ...

  4. mongodb-linux-x86_64

    卷 DataDisk 的文件夹 PATH 列表卷序列号为 4A8E-D95CD:.│  1.txt│  GNU-AGPL-3.0│  MPL-2│  README│  THIRD-PARTY-NOTI ...

  5. c#导出文件,下载文件,命名下载后的文件名

    Page.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpU ...

  6. 【bzoj3682】Phorni

    后缀平衡树裸题. 后缀平衡树呢,实际上是一个很naive的东西.就是用平衡树维护后缀数组. 这样的话就可以支持在最前端插入一个字符(相当于插入新的后缀) 每次比较节点的tag是O(1)的,所以可以快速 ...

  7. 2017多校第9场 HDU 6166 Senior Pan 堆优化Dij

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6166 题意:给你一个有向图,然后给你k个点,求其中一个点到另一个点的距离的最小值. 解法:枚举二进制位 ...

  8. memcached基本操作和语法

    一.基本语法 <command name><key><flags><exptime><bytes>\r\n<data block> ...

  9. JDBC数据源连接池(1)---DBCP

    何为数据源呢?也就是数据的来源.我在前面的一篇文章<JDBC原生数据库连接>中,采用了mysql数据库,数据来源于mysql,那么mysql就是一种数据源.在实际工作中,除了mysql,往 ...

  10. maven项目的多级目录

    刚刚把一个开源的项目变成maven项目来进行管理,由于是多级的目录(以前配置的都是单级的目录),所以记录一下pom文件是怎么配置的. 一.目录结构 如下,maven的结构图,红字是表示完整的项目