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& ...
随机推荐
- Java—将文件压缩为zip文件
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import ...
- PHP中单例模式与工厂模式
单例模式概念 单例模式是指整个应用中类只有一个对象实例的设计模式. 单例模式的特点 一个类在整个应用中只有一个实例 类必须自行创建这个实例 必须自行向整个系统提供这个实例 php中使用单例模式的原因 ...
- [ Java ] [ UT ] [ Mock ] [ JUnit ] 單元測試的撰寫
最近新的專案用到很多的單元測試,對於單元測試有多了一歇的了解. 先寫下大綱,後面分篇寫出總結心得. 1. 單元測試要隔離對外部的關聯 2. Mock, spy 的用法時機差異 3. JUnit 4, ...
- 控制台——对WIN32 API的使用(user32.dll)
Win32 API概念:即为Microsoft 32位平台的应用程序编程接口(Application Programming Interface).所有在Win32平台上运行的应用程序都可以调用这些函 ...
- [Windows Server 2003] 还原SQL Server数据库
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:SQL Ser ...
- (转)OGNL与值栈
http://blog.csdn.net/yerenyuan_pku/article/details/67709693 OGNL的概述 什么是OGNL 据度娘所说: OGNL是Object-Graph ...
- What is the difference between Gradle Build and Gradle Sync?
Gradle Build helps you to compile your Android app into an APK while Gradle Sync will sync up all yo ...
- js 不能用关键字 delete 做函数名
把delete更改为mydelete正常.
- Redis事物及锁的运用
redis与mysql事物比较如下: 下面是一个redis事物运用于买票的demo
- jquery ajax中各个事件执行顺序如下
$(function(){ setTimeout(function(){ $.ajax({ url:'/php/selectStudent.php', }); },0); $(document).aj ...