HDU 5288 OO’s Sequence 水题
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 水题的更多相关文章
- 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——————【技巧题】
OO’s Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- Hdu 5288 OO’s Sequence 2015多小联赛A题
OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- HDU 5288 OO‘s sequence (技巧)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5288 题面: OO's Sequence Time Limit: 4000/2000 MS (Jav ...
- HDOJ 5288 OO’s Sequence 水
预处理出每一个数字的左右两边能够整除它的近期的数的位置 OO's Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 13 ...
- hdu 5288 OO’s Sequence(2015 Multi-University Training Contest 1)
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 枚举+二分
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)之和. 解法:第一次打多校……心里还有点小激动……然而一道签到题做了俩点……呜呜呜… ...
随机推荐
- Join vs merge vs lookup
The obvious benefit of merge over join is the ability to add reject links. I can't upload pictures. ...
- 网络设备之pci_device_id
标准PCI设备都有一个配置寄存器,用来存储各种参数: /* pci设备配置寄存器 */ struct pci_device_id { /* 厂商id,设备id */ __u32 vendor, dev ...
- Linux信号函数
1. signal函数: #include <signal.h> void (*signal(int signo, void (*func)(int)))(int); ret-成功返回信号 ...
- 64_c1
CBFlib-0.9.5.15-3.fc26.i686.rpm 05-Feb-2017 21:55 427710 CBFlib-0.9.5.15-3.fc26.x86_64.rpm 05-Feb-20 ...
- 【Android开发日记】之入门篇(十五)——ViewPager+自定义无限ViewPager
ViewPager 在 Android 控件中,ViewPager 一直算是使用率比较高的控件,包括首页的banner,tab页的切换都能见到ViewPager的身影. viewpager 来源自 v ...
- Linux Python apache的cgi配置
一.找到安装Apache的目录/usr/local/apache2/conf,并对httpd.conf配置文件进行修改 1.加载cgi模块 去掉注释: LoadModule cgid_module m ...
- Django Ajax学习二之csrf跨站请求伪造
方式1 $.ajaxSetup({ data: {csrfmiddlewaretoken: '{{ csrf_token }}' }, }); 方式2 # html文件from表单中<form& ...
- Django web框架之权限管理二
1. login登录 def login(request): if request.method=="GET": return render(request,'login.html ...
- JavaScript备忘录-闭包(2)
闭包的定义 闭包是指函数有自由独立的变量.换句话说,定义在闭包中的函数可以“记忆”它创建时候的环境. 闭包的浅显理解 function makeFunc() { var name = "Mo ...
- LoadRunner运行中的mmdrv和mdrv
在LoadRunner运行脚本过程中,在任务管理器中我们可以看到有一个或多个名为“mmdrv”的进程在运行,与此同时当我们查看LoadRunner\bin目录下的文件时还会看到一个“mdrv.exe” ...