HDU 5288
//枚举因子,查找和i最近的左右是i因子的点即可。 #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define LL long long
using namespace std; const int MAX=100010;
const LL mod=1e9+7;
int l_next[10010];
int r_next[10010];
int num[MAX];
int l[MAX],r[MAX]; int main(){
int n;
while(scanf("%d",&n)!=EOF){
for(int i=1;i<=n;i++){
scanf("%d",&num[i]);
l[i]=0;r[i]=MAX;
}
for(int i=0;i<10010;i++){
l_next[i]=0; r_next[i]=MAX;
}
for(int i=1;i<=n;i++){
int lmax=0;
for(int k=1;k*k<=num[i];k++){
if(num[i]%k==0){
lmax=max(lmax,l_next[k]);
// if(k!=1)
lmax=max(lmax,l_next[num[i]/k]);
}
}
l[i]=lmax;
l_next[num[i]]=i;
}
/* for(int i=1;i<=n;i++)
cout<<l[i]<<" ";
cout <<endl;*/
for(int i=n;i>=1;i--){
int rmin=n+1;
for(int k=1;k*k<=num[i];k++){
if(num[i]%k==0){
rmin=min(rmin,r_next[k]);
// if(k!=1)
rmin=min(rmin,r_next[num[i]/k]);
}
}
r[i]=rmin;
r_next[num[i]]=i;
}
/* for(int i=1;i<=n;i++)
cout<<r[i]<<" ";
cout <<endl;
*/
LL ans=0;
for(int i=1;i<=n;i++){
ans+=(LL)(i-l[i])*(LL)(r[i]-i);
ans%=mod;
}
printf("%lld\n",ans); }
return 0;
}
HDU 5288的更多相关文章
- hdu 5288||2015多校联合第一场1001题
pid=5288">http://acm.hdu.edu.cn/showproblem.php?pid=5288 Problem Description OO has got a ar ...
- 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 ...
- HDU 5288 OO‘s sequence (技巧)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- 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 ...
- HDU 5288 OO’s Sequence 水题
OO's Sequence 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...
- hdu 5288 数学 ****
给一个序列 定义函数f(l ,r) 为区间[l ,r] 中 的数ai不是在这个区间其他任意数aj的倍数 求所有f(l,r)之和 通过预处理,记录 a[i] 的左右边界(所谓的左右边界时 在从 a[i] ...
- 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 ...
- HDU 5288 OO’s Sequence
题意:给一个序列,函数f(l, r)表示在[l, r]区间内有多少数字不是其他数字的倍数,求所有区间的f(l, r)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...
- 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 ...
- HDU 5288 OO’s Sequence
题意: 给你一个序列, 有一个函数 F(L,R) 其中 ai 均不能 被 aL - aR整除的 函数值是这个ai个数 思路 : 反过来求 满足这样的条件的 ai 的区间,然后求和 #include& ...
随机推荐
- oracle 误删数据
insert into hr.job_history select * from hr.job_history as of timestamp to_timestamp('2007-07-23 10: ...
- JS/JQuery操作DOM元素笔记
原因 自己目前在搭建一个.NET Core的框架,正在构建权限这块的东西,今天设置权限界面,需要使用JavaScript操作DOM元素,记录一下. 页面大概是酱紫的(我使用的AdminLTE和LayU ...
- IIS 配置 SVC
IIS8中添加WCF支持几种方法小结[图文] 方法一 最近在做Silverlight,Windows Phone应用移植到Windows 8平台,在IIS8中测试一些传统WCF服务应用,发现IIS8不 ...
- Unity学习-预制(四)
预制即克隆 比如要模拟一个下雨的场景,天下掉下来一颗一颗的雨滴.如果此时,我们给每一个雨滴创建一个对象的话,那会很浪费资源,而且也没必要,因为所有的雨滴是相同的.这个时候就使用到了预制,一种可以被重复 ...
- [ JSOI 2015 ] Salesman
\(\\\) \(Description\) 给出一棵以\(1\)为根的\(N\)个节点的树,开始的时候你在\(1\)号节点. 除了\(1\)号节点以外,每个点都有访问次数限制\(t_i\),即到达该 ...
- 常用animation动画
/*编辑动画名*/ animation-name: myDemo; /*动画持续时间*/ animation-duration: 6s; /*动画方向*/ /*reverse 反向*/ /*alter ...
- enc28j60网卡驱动模块添加进linux内核,Kconfig,Makefile配置过程
这里是要把http://www.cnblogs.com/hackfun/p/6260396.html中的enc28j60网卡驱动模块,添加到2.6.22.6内核中,这个模块代码不需要任何修改.只需要在 ...
- Win32最简单的程序
#include<tchar.h> #include<stdio.h> #include<windows.h> LRESULT CALLBACK WinSunPro ...
- IP访问频率限制不能用数组循环插入多个限制条件原因分析及解决方案
14.IP频率限制不能用数组循环插入多个限制条件原因分析及解决方案: define("RATE_LIMITING_ARR", array('3' => 3, '6' => ...
- servlet-请求重定向
package servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.ser ...