OO’s Sequence

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 2643    Accepted Submission(s): 925

Problem 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=1nj=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
 
Author
FZUACM
 
Source
 
Recommend
 
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
#include<vector>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000007)
#define MAXN (1000000+10)
#define MAXn (1000000+10)
typedef long long ll;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int a[MAXn],n;
ll l[MAXN],r[MAXN];
ll al[MAXN],ar[MAXN];
int main()
{
// freopen("A.in","r",stdin);
// freopen(".out","w",stdout); while(scanf("%d",&n)==1)
{
ll ans=0;
For(i,n) scanf("%d",&a[i]);
MEM(l) MEMI(r)
For(i,n)
{
al[i]=0;
int p=a[i];
for(int j=1;(ll)j*j<=(ll)p;j++) {
if (p%j==0) al[i]=max(al[i],max(l[j],l[p/j]));
}
l[a[i]]=i;
} ForD(i,n)
{
ar[i]=n+1;
int p=a[i];
for(int j=1;(ll)j*j<=(ll)p;j++) {
if (p%j==0) ar[i]=min(ar[i],min(r[j],r[p/j]));
}
r[a[i]]=i;
} // For(i,n) cout<<al[i]<<' ';cout<<endl;
// For(i,n) cout<<ar[i]<<' ';cout<<endl;
// For(i,n)
upd(ans,mul(i-al[i],ar[i]-i));
cout<<ans<<endl;
} return 0;
}

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 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5288 Description OO has got a array A ...

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

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

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

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

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

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

  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(计数)

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

随机推荐

  1. 暑假集训 || bitset

    bitset是一个存储0和1的数组 可以快速的把两个bitset的每一位对应做与或啥的 在可以用01串表示某个状态的时候可以应用到它 就是有两个集合,求它们的交集 bitset <> a, ...

  2. java中等待所有线程都执行结束

    转自:http://blog.csdn.net/liweisnake/article/details/12966761 今天看到一篇文章,是关于java中如何等待所有线程都执行结束,文章总结得很好,原 ...

  3. linux下使用docker方式部署ftp服务器

    linux环境下部署vsftpd比较繁琐,可以直接使用docker官方仓库中的pure-ftpd镜像来部署ftp服务器. 下载镜像 docker pull stilliard/pure-ftpd:ha ...

  4. 如何学好C++语言(转)

    不久前发现陈皓的blog -- 酷壳,闲暇之余看看,学到不少东西,感觉作为一个程序员自己才刚开始也还有很长的路需要去走.真后悔本科到研究生的6年间看书不够,那只有从现在起不断的学习.最近有李开复老师得 ...

  5. pwntools各使用模块简介

    pwntools pwntools 是一款专门用于CTF Exploit的python库,能够很方便的进行本地与远程利用的切换,并且里面包含多个模块,使利用变得简单.可以在github上直接搜索pwn ...

  6. p3386 二分图匹配模板

    https://www.luogu.org/problemnew/show/P3386 可以只做一边的匹配 #include <bits/stdc++.h> using namespace ...

  7. html5的导出表格功能

    最近遇到一个需要导出表格的需求,研究了一下nodeJs的excel模块及好多其他的插件,发现还是蛮复杂的,由于项目对于表格的要求不高,因此同事推荐了一种h5的表格导出生成方法,比较简单,在此记录一下 ...

  8. Java学习之理解递归

    Java支持递归.递归是根据自身定义内容的过程.就Java编程而言,递归是一个允许方法调用自身的特性.调用自身的方法被称为递归.典型的例子就是阶乘的计算,N的阶乘就是从1到N之间所有整数的乘积. 当方 ...

  9. 遇到的Ajax相关问题

  10. 【HTML/XML 6】XML文档的基本组成

    导读:大致上,一个XML文档可以由三个部分组成,即声明区.定义区和文档主体区.在XML文档中,各个组成部分都包含特定的内容,有着不同的作用.本篇博客,通过分析上篇博客中的XML实例,来了解XML文档 ...